chris17 Posted February 24, 2014 Share Posted February 24, 2014 I would appreciate any form of help to this problem: I have two tables named doctors and fields with a one to many relationship with the field being the one part and doctors the many part. My form is supposed to insert into the doctors' table and as well select has a select option the chooses from already existing fields in the fields table. The name of my foreign key in the doctors' table is "field_id". How can i this insert in the two tables? Quote Link to comment https://forums.phpfreaks.com/topic/286492-how-to-insert-into-two-related-tables-using-a-single-form/ Share on other sites More sharing options...
ginerjm Posted February 24, 2014 Share Posted February 24, 2014 Why do you need to insert into two tables? Quote Link to comment https://forums.phpfreaks.com/topic/286492-how-to-insert-into-two-related-tables-using-a-single-form/#findComment-1470493 Share on other sites More sharing options...
chris17 Posted February 24, 2014 Author Share Posted February 24, 2014 Thanks for your attention. I just realized i dont have to insert into the two tables instead i would just update the foreign key that is in doctors. But how the form is to be filed is using the field names. I dont know if you can get the picture of what am trying to explain. Thanks once more Quote Link to comment https://forums.phpfreaks.com/topic/286492-how-to-insert-into-two-related-tables-using-a-single-form/#findComment-1470497 Share on other sites More sharing options...
ginerjm Posted February 24, 2014 Share Posted February 24, 2014 You're right. I don't understand anything you just wrote. Quote Link to comment https://forums.phpfreaks.com/topic/286492-how-to-insert-into-two-related-tables-using-a-single-form/#findComment-1470498 Share on other sites More sharing options...
chris17 Posted February 24, 2014 Author Share Posted February 24, 2014 <?php include("includes/database.php"); ?> <!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=iso-8859-1" /> <title>NHIS - Doctors' Registration</title> <link rel="stylesheet" type="text/css" href="styles/reg_doc.css"> </head> <body> <div id = "container"> <div id = "header"><a href="">Back to Home</a></div> <div id = "title"><h3>DOCTOR'S REGISTRATION FORM</h3></div> <div id = "content"> <div id = "form_cont"> <form id="form1" name="form1" method="post" action="create_doctor.php"> <fieldset> <fieldset> <label for="email"><span>Email Address:</span> <input type="text" name="email" id="email"/> </label> <label for="pass"><span>Password:</span> <input type="password" name="pass" id="pass"/> </label> <label for="pass_conf"><span>Confirm Password:</span> <input type="password" name="pass_conf" id="pass_conf"/> </label> </fieldset> <fieldset> <label for="Fname"><span>First Name:</span> <input type="text" name="Fname" id="Fname"/> </label> <label for="Lname"><span>Last Name:</span> <input type="text" name="Lname" id="Lname"/> </label> <label for="Sname"><span>Surname:</span> <input type="text" name="Sname" id="Sname"/> </label> <?php $fields = mysql_query("SELECT * FROM field",$connection); if(!$fields){ die("Error1: " . mysql_error()); } ?> <label for="field"><span>Field:</span> <select name="field"> <?php while($row = mysql_fetch_array($fields)){ echo "<option value=\"{$row["field"]}\" > {$row["field"]} </option>" ; } ?> </select> </label> </fieldset> <fieldset class="f1"> <label for="address"><span>Address:</span> <input type="text" name="address" id="address"/> </label> <label for="dob"><span>DOB:</span> <input type="text" name="dob" id="dob"/> </label> </fieldset> <fieldset> <label for="gender"><span>Gender:</span> <input type="radio" name="gender" value = "Male"/> Male <br/ > <input type="radio" name="gender" value = "Female"/> Female </label> </fieldset> </fieldset> <div> <input id="buttondiv" type="submit" name="submit" value="REGISTER"/> </div> </form> </div> </div> </body> </html> This is the doctors' form. How can i insert into my database? Quote Link to comment https://forums.phpfreaks.com/topic/286492-how-to-insert-into-two-related-tables-using-a-single-form/#findComment-1470500 Share on other sites More sharing options...
ginerjm Posted February 24, 2014 Share Posted February 24, 2014 Where is your php code? HTML does nothing for me. Quote Link to comment https://forums.phpfreaks.com/topic/286492-how-to-insert-into-two-related-tables-using-a-single-form/#findComment-1470502 Share on other sites More sharing options...
chris17 Posted February 24, 2014 Author Share Posted February 24, 2014 I have written none yet. The only php is in the html and it pulls up all the fields in the field table to the select option. What I wish to do is to insert this into my database with respect to the selected option. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/286492-how-to-insert-into-two-related-tables-using-a-single-form/#findComment-1470506 Share on other sites More sharing options...
ginerjm Posted February 24, 2014 Share Posted February 24, 2014 When you get something written and want help with it, post it. Quote Link to comment https://forums.phpfreaks.com/topic/286492-how-to-insert-into-two-related-tables-using-a-single-form/#findComment-1470507 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.