jensvanherck Posted December 20, 2009 Share Posted December 20, 2009 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 I hope somebody understands what i mean Thank you for your time, Jens Van Herck Link to comment https://forums.phpfreaks.com/topic/185813-phpmysql-i-need-some-help-with-an-idea/ Share on other sites More sharing options...
cags Posted December 21, 2009 Share Posted December 21, 2009 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 https://forums.phpfreaks.com/topic/185813-phpmysql-i-need-some-help-with-an-idea/#findComment-981488 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.