Colton.Wagner Posted September 12, 2011 Share Posted September 12, 2011 I have tried this for about 2 solid hours and I cannot figure out how to make multiple forms that have the same ID. Definition: I have 3 pages and they all have different information that needs to be placed into the database. I have no problem doing that the trouble comes when I try to make the 3 different database entry's have the same ID as the first form. My thought was to have the first form be completed then after the data was placed it would use mysql to pull the ID back out by using the WHERE clause to match the persons last name. //Connection to the Mysql_Database $con = mysql_connect("####", "####", "####"); if(!$con){ die("There was an error connecting to your mysql_database" . mysql_error()); } //Variables to be entered into Patient_Data $last_name = $_POST['last_name']; //Intialize and Select the correct database. mysql_select_db("####"); //Format the data for entry into the mysql Database. $query = mysql_query("INSERT INTO Patient_Data VALUES ('', '$last_name)"); //Verify that the operation has worked if(!$query){ die("Lost in Transmission!" . mysql_error()); } $id_find = mysql_query("SELECT * FROM #### WHERE last_name='$last_name'"); while($id = mysql_fetch_row($id_find)){?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form name="MedicalHistory" action="https://evansvillesurgical.com/med-record.php?id=<?php echo $id['id'];}?>" enctype="application/x-www-form-urlencoded" method="post"> Any help would be greatly appreciated. Even if it's just describing in Pseduo code a better way to go about this. Thanks, Colton Wagner Quote Link to comment https://forums.phpfreaks.com/topic/246991-multipage-form-using-mysqls-ai/ Share on other sites More sharing options...
Pikachu2000 Posted September 12, 2011 Share Posted September 12, 2011 You can use mysql_insert_id() to get the PK ID number of the record, then use it to UPDATE the record with subsequent forms. Another way would be to store the form data in a $_SESSION variable for each form, then INSERT it all at once, after the last form has been submitted. Quote Link to comment https://forums.phpfreaks.com/topic/246991-multipage-form-using-mysqls-ai/#findComment-1268484 Share on other sites More sharing options...
Colton.Wagner Posted September 12, 2011 Author Share Posted September 12, 2011 Pikachu2000, Thank you very much. I was wasting code and processing speed. You solved it with a quick command. Probably should have done a little more research but I was looking through php.info rather than Mysql. Thanks, Colton Wagner Quote Link to comment https://forums.phpfreaks.com/topic/246991-multipage-form-using-mysqls-ai/#findComment-1268487 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.