How to insert record into two mysql table using php? -
i have 2 tables in database 1 "test1" , second "test2". , field test 1 "id","survey_no","lastname" , field of test have "id","survey_no","address" id test1 , test2 primary key , set auto-increment..what want here ever insert in "survey_no" in test1 should insert inserted in "survey_no in test2"..can please me it..please..
i have here code insertion called sample.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=utf-8" /> <title>untitled document</title> </head> <body> <form method="post" class="signin" action="" name="add" id="form1"> <fieldset class="textbox"> <label class="province_id"> <span>province id</span> <input id="province" name="survey_no" type="number" value="" autocomplete="on" placeholder="survey_no"> </label> <label class="municipality"> <span>municipality</span> <input id="municipality" name="lastname" value="" type="text" autocomplete="on" placeholder="lastname"> </label> <br /> <br /> <button id="submit" type="submit" name="submit">save</button> <button id="submit" type="reset" name="reset">reset</button> </fieldset> <?php $conn=mysql_connect('localhost','root',''); if(!$conn) { die('could not connect:' .mysql_error()); } mysql_select_db("sample",$conn); if(isset($_post['submit'])) { $survey_no=$_post['survey_no']; $lastname=$_post['lastname']; $result = mysql_query("insert `test1`(survey_no,lastname) values ('$survey_no','$lastname')"); if($result) { echo "<script type=\"text/javascript\">". "alert('saved!');". "</script>"; } else{ echo "<script type=\"text/javascript\">". "alert('failed!');". "</script>"; } } ?> </form> </body> </html>
so far understand want this
$result = mysql_query("insert `test1`(survey_no,lastname) values ('$survey_no','$lastname')"); $result1 = mysql_query("insert `test2`(survey_no) values ('$survey_no')");
Comments
Post a Comment