joshuaceo Posted December 5, 2008 Share Posted December 5, 2008 This is the form: <html> <body> <form action="insert.php" method="post"> Newsletters: <input type="text" name="newsletters" /><br><br> Updates: <input type="text" name="updates" /><br><br> First Name: <input type="text" name="fname" /><br><br> Last Name: <input type="text" name="lname" /><br><br> Login: <input type="text" name="login" /><br><br> Password: <input type="text" name="password" /><br><br> Company: <input type="text" name="company" /><br><br> Address: <input type="text" name="address1" /><br><br> Address2: <input type="text" name="address2" /><br><br> City: <input type="text" name="city" /><br><br> State: <input type="text" name="state" /><br><br> Province: <input type="text" name="province" /><br><br> Zip: <input type="text" name="zip" /><br><br> Country: <input type="text" name="country" /><br><br> Email: <input type="text" name="email" /><br><br> Email Mode: <input type="text" name="email_mode" /><br><br> Phone: <input type="text" name="phone" /><br><br> <input type="submit" /> </form> </body> </html> This is insert.php <?php $con = mysql_connect("localhost","crown_brownu","asdfasdf"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("crown_brownies", $con); $password=md5($_POST[password]); $sql="INSERT INTO users (newsletters, updates, fname, lname, login, password, company, address1, address2, city, state, province, zip, country, email, email_mode, phone) VALUES ('$_POST[newsletters]','$_POST[updates]','$_POST[fname]','$_POST[lname]','$_POST[login]','$password','$_POST[company]','$_POST[address1]','$_POST[address2]','$_POST[city]','$_POST[state]','$_POST[province]','$_POST[zip]','$_POST[country]','$_POST[email]','$_POST[email_mode]','$_POST[phone]')"; $sql="INSERT INTO users_shipping (address1, address2, city, state, province, zip, country) VALUES ('$_POST[address1]','$_POST[address2]','$_POST[city]','$_POST[state]','$_POST[province]','$_POST[zip]','$_POST[country]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 user added"; mysql_close($con) ?> Will this work correctly by sending the same information to 2 different tables? I hope someone can help Quote Link to comment https://forums.phpfreaks.com/topic/135668-i-need-help-importing-information-to-2-tables-with-1-form/ Share on other sites More sharing options...
fenway Posted December 5, 2008 Share Posted December 5, 2008 Why wouldn't it? Quote Link to comment https://forums.phpfreaks.com/topic/135668-i-need-help-importing-information-to-2-tables-with-1-form/#findComment-706845 Share on other sites More sharing options...
joshuaceo Posted December 5, 2008 Author Share Posted December 5, 2008 The reason is I really don't know anything about php and wanted to know if it would work like I have it above. So this should work without any problems? or is there a better way to have the insert.php file? Quote Link to comment https://forums.phpfreaks.com/topic/135668-i-need-help-importing-information-to-2-tables-with-1-form/#findComment-706882 Share on other sites More sharing options...
fenway Posted December 5, 2008 Share Posted December 5, 2008 Well, to insert into 2 tables you need 2 insert statements, so there's "other way". I would print out a location header to make sure that it doesn't get POSTed twice.. .but that's not a mysql issue anymore. Quote Link to comment https://forums.phpfreaks.com/topic/135668-i-need-help-importing-information-to-2-tables-with-1-form/#findComment-706913 Share on other sites More sharing options...
joshuaceo Posted December 5, 2008 Author Share Posted December 5, 2008 Can you show me the code to do it the way you mentioned? I really don't know much about php. I hope you can help and thanks so much! Quote Link to comment https://forums.phpfreaks.com/topic/135668-i-need-help-importing-information-to-2-tables-with-1-form/#findComment-706953 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.