/    Sign up×
Community /Pin to ProfileBookmark

Echo unique id – MySQL

Hello,

I have set the “id”-column in my MySQL table to “auto_increment”.

I use INSERT INTO to write to the table. This works fine as MySQL automatically assigns a new, unique value to the “id”-column in my table.

After the new entry has been registered in the MySQL table I need to echo the new unique value (which is now stored in the “id”-column). However, I do not know how to do this as there is no <input> tag with the name “id” on the preceding page.

Would appreciate your help.

Regards

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@AdamBrillJun 03.2005 — I believe you are looking for [URL=http://us3.php.net/manual/en/function.mysql-insert-id.php]mysql_insert_id[/URL].
Copy linkTweet thisAlerts:
@magoauthorJun 03.2005 — Wow, that was simple! Thanks a lot.

By the way, is there any particular reason why I should use printf and not just print? I tried them and they both work with mysql_insert_id().

Regards
Copy linkTweet thisAlerts:
@AdamBrillJun 03.2005 — printf to print? Well, technically you should just use [URL=http://us3.php.net/manual/en/function.echo.php]echo[/URL], since the difference is just that echo doesn't return a result, which makes it a little easier on the server. It doesn't make a huge difference, but unless you need to get a result from it, which is doubtful, it is just good practice to use the least server-intensive option.
Copy linkTweet thisAlerts:
@NogDogJun 03.2005 — printf() allows you to use a format string as described in the [url=http://www.php.net/sprintf]sprintf documentation[/url], such as:
[code=php]
$value = 12.3456;
printf('Price: $%04.2f', $value);
[/code]

...which would output...
<i>
</i>Price: $0012.35
Copy linkTweet thisAlerts:
@magoauthorJun 03.2005 — NogDog and AdamBrill,

Thanks to both of you!

Regards
Copy linkTweet thisAlerts:
@maiochineMay 16.2010 — Hi guys !

I am making a registration form, I would not like to have the users creating their own user ID but I wish to have an

automated system that creates a predefined user ID, like for example CIV1000 and it auto increments so next user

would be CIV1001 than CIV1002 and so on...


Would you please lead me ? I'm a newbe on php and MySql, I followed several tutorials but they all have the username

entry in their form ... would you please give me a hand ?


Thank you in advance.
Copy linkTweet thisAlerts:
@Jarrod1937May 16.2010 — Hi guys !

I am making a registration form, I would not like to have the users creating their own user ID but I wish to have an

automated system that creates a predefined user ID, like for example CIV1000 and it auto increments so next user

would be CIV1001 than CIV1002 and so on...


Would you please lead me ? I'm a newbe on php and MySql, I followed several tutorials but they all have the username

entry in their form ... would you please give me a hand ?


Thank you in advance.[/QUOTE]

For help you should create your own topic, you'll probably get better responses that way. Though i personally would recommend not creating user id's (i'm assuming doe login purposes?) through auto incrementing for security reasons... after all its not too hard to guess that if there is a CIV1002 then there is probably a CIV1001 which would just make the act of brute forcing random accounts that much easier.
Copy linkTweet thisAlerts:
@ilbonparaurtiMay 16.2010 — Is there a PDO equiv?
×

Success!

Help @mago spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...