Jump to content

[php/Mysql] I need some help with an idea


jensvanherck

Recommended Posts

Greetings all,(I hope this is the right board to ask this kind of question)

I just got an idea for something but I don't really know how to implement / write the script...

I hope I'm not to vague...

so i have a form with several fields.

when the fields are submitted I want to  check if the value in 1 of the fields already exists (like a city name for example) => when it exist get the ID that is given to it by autoincrement

=>when it doesn't exist create the value in the mysql db and then get the ID

....

=> then use the ID for use with the other values that are within the other fields and submit it to an other mysql table

 

:o I hope somebody understands what i mean

 

Thank you for your time,

Jens Van Herck

Link to comment
Share on other sites

It sounds like your after something like this...

 

$result = mysql_query("SELECT id FROM table WHERE name=$name");

if(mysql_num_rows($result) != 0) {
   $id = mysql_fetch_result($result, 0);
} else {
   mysql_query("INSERT INTO table (field1, field2) VALUES ('$value1', '$value2')");
   $id = mysql_insert_id();
}

Link to comment
Share on other sites

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.