Jump to content

Recommended Posts

Hello,

 

I have a problem that I can not solve. For ease of communication lets say that I have a registration from where people fill out their first mane and hit submit (lets say John is filling out the form). Once submitted the data travels to my database where new record is created, John is put under "name1" column, as well as ID that is unique to each record. How do I set the database in such manner that it combined those two columns into one (a third one, like "name2") so the end result is something like John32?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/184858-associating-field-and-id-in-database/
Share on other sites

something like this:

 

//some name here
$name1 = 'something';

//just insert the first name for now
$query = mysql_query("INSERT INTO table(name1) VALUES ('$name1')");

//gets the last id
$last_id = mysql_insert_id();

//once we have the id and the record there we can just update it with the name1 and last_id
$another_query = mysql_query("UPDATE table SET name2 ='$name1.$last_id' WHERE id='$last_id'");

 

hopefully that helps. There is a mysql function called last_insert_id() but I think that will be the same type of method i did here, but figured id mention it if you wanted to look into it.

One more question with this.

After the form is filled and submitted I have a PHP page that says something like: Thank you "john" (name entered in the form) for registering. I am having through. saying: your registration id is "John32" (what the previous question asked). How do I recall that from the database. I can not figure it out.

 

Thanks a lot

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.