sr20rps13 Posted February 5, 2007 Share Posted February 5, 2007 <html> <head> <title>Add new customer info.</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php if(isset($_POST['add'])) { include 'mysql_config.php'; include 'mysql_connect.php'; $First_name = $_POST['first_name']; $Last_name = $_POST['last_name']; $Address = $_POST['address']; $Phone_number = $_POST['phone_number']; $Email = $_POST['email']; $query = "INSERT INTO customr_data (first_name, last_name, address, phone_number, email) values (FIRST_NAME ('$First_name'), LAST_NAME ('$Last_name'), ADDRESS ('$Address'), PHONE_NUMBER ('$Phone_number'), EMAIL ('$Email')"; mysql_query($query) or die('mysql_error'); $query = "FLUSH PRIVILEGES"; mysql_query($query) or die('Error, insert query failed'); include 'mysql_close.php'; echo "New customer added"; } else { ?> <form method="post"> <table width="400" border="0" cellspacing="1" cellpadding="2"> <tr> <td width="100">First name</td> <td><input name="first_name" type="text" id="first_name"></td> </tr> <tr> <td width="100">Last name</td> <td><input name="last_name" type="text" id="last_name"></td> </tr> <tr> <td width="100">Address</td> <td><input name="address" type="text" id="address"></td> </tr> <tr> <td width="100">Phone Number</td> <td><input name="phone_number" type="text" id="phone_number"></td> </tr> <tr> <td width="100">Email</td> <td><input name="email" type="text" id="email"></td> </tr> <tr> <td width="100"> </td> <td> </td> </tr> <tr> <td width="100"> </td> <td><input name="add" type="submit" id="add" value="Add customer"></td> </tr> </table> </form> <?php } ?> </body> </html> Can someone tell me how I can make it so that it displays the mysql error message rather than mysql_error. Also, could someone exam my code and tell me where I went wrong? Link to comment https://forums.phpfreaks.com/topic/37210-solved-grr-form-wont-submit-data-to-mysql/ Share on other sites More sharing options...
papaface Posted February 5, 2007 Share Posted February 5, 2007 Yes, you arent writing the SQL correctly. Should be: $query = "INSERT INTO customr_data (first_name, last_name, address, phone_number, email) values ($First_name, $Last_name,$Address,$Phone_number, $Email)"; Link to comment https://forums.phpfreaks.com/topic/37210-solved-grr-form-wont-submit-data-to-mysql/#findComment-177764 Share on other sites More sharing options...
redphoenix Posted February 5, 2007 Share Posted February 5, 2007 hey! the one line answer: instead of having die('mysql_error'), change that to die(mysql_error()) That should print out the error message or you could do this, so that the page doesn't look incomplete in case of error: mysql_quer(...) or $error = mysql_error(); and in the next line, if (isset($error)) { skip other lines } and "nicely display error message", so that the page doesn't look incomplete in case of error. Link to comment https://forums.phpfreaks.com/topic/37210-solved-grr-form-wont-submit-data-to-mysql/#findComment-177765 Share on other sites More sharing options...
troy_mccormick Posted February 5, 2007 Share Posted February 5, 2007 Yes, you arent writing the SQL correctly. Should be: $query = "INSERT INTO customr_data (first_name, last_name, address, phone_number, email) values ($First_name, $Last_name,$Address,$Phone_number, $Email)"; Remember that you will probably need quotes around your text (varchar in your database) values: ('$First_name', '$Last_name','$Address','$Phone_number', '$Email')"; Link to comment https://forums.phpfreaks.com/topic/37210-solved-grr-form-wont-submit-data-to-mysql/#findComment-177766 Share on other sites More sharing options...
sr20rps13 Posted February 5, 2007 Author Share Posted February 5, 2007 Ahh thank you all, I've figured it out with the mysql error message. Turns out there was no database selected in the connect file. Ty. Link to comment https://forums.phpfreaks.com/topic/37210-solved-grr-form-wont-submit-data-to-mysql/#findComment-177769 Share on other sites More sharing options...
sr20rps13 Posted February 5, 2007 Author Share Posted February 5, 2007 <solved> Link to comment https://forums.phpfreaks.com/topic/37210-solved-grr-form-wont-submit-data-to-mysql/#findComment-177791 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.