predwine Posted March 10, 2011 Share Posted March 10, 2011 I'm new to mysql. I created a form to enter data into a table, but the data does not get into the table. Here's the form at http://test.paulredwine.com/db2/add_contacts.htm : <html><body><form action=contact_submit_form.php method=GET> Contact Type: <select name="Contact Type"> <option value="1">--Contact Type--</option> <option value="2">Customer - Active</option> <option value="3">Customer - Inactive</option> <option value="4">Customer - Canceled</option> </select><br> Name (Last, First): <input type=text name=Name size=25 maxlength=25><br> Address: <input type=text name=Address size=25 maxlength=25><br> City: <input type=text name=City size=25 maxlength=25><br> State: <input type=text name=State size=25 maxlength=25><br> Postal Code: <input type=text name=PostalCode size=25 maxlength=25><br> <p> <input type=submit> </form></body></html> and here is contact_submit_form.php: <html> <body> <?php mysql_connect (localhost, predwine_test, jazz77); mysql_select_db (predwine_test); mysql_query ("INSERT INTO contacts (contactType, Name, Address, City, State, PostalCode) VALUES ('$ContactType', '$Name', '$Address', '$City', '$State', '$PostalCode') "); print ($ContactType); print (" "); print ($Name); print ("<p>"); print ("Thanks for your submission."); ?> </body></html> It appears that the form works, because I get the confirmation, "Thanks for your submission" but the data never reaches the database table. Link to comment https://forums.phpfreaks.com/topic/230258-data-does-not-get-into-the-table-from-form/ Share on other sites More sharing options...
TOA Posted March 10, 2011 Share Posted March 10, 2011 Please use the forum code tags The way you have it, it will print no matter what. I would add some error handling. (The reason it was saying "Thank you..." even with an error) Also, add or die() for testing $connection = mysql_connect (localhost, predwine_test, jazz77); $db = mysql_select_db (predwine_test); $sql = "INSERT INTO contacts (contactType, Name, Address, City, State, PostalCode) VALUES ('$ContactType', '$Name', '$Address', '$City', '$State', '$PostalCode')"; $query = mysql_query ($sql) or die(mysql_error()); if (!$query) { print ("ERROR"); } else { print ($ContactType]); print (" "); print ($Name); print ("<p>"); print ("Thanks for your submission."); } Try that and let me know if it helps; it's not tested and just what I noticed at first glance Link to comment https://forums.phpfreaks.com/topic/230258-data-does-not-get-into-the-table-from-form/#findComment-1185800 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.