maideen Posted April 7, 2014 Share Posted April 7, 2014 Hi I am new in php. I could not insert the data into mysql table. and there is no error prompt Below is my code. Pls help me. <?php include_once '../inc/header.php'; if (isset($_POST['submit']) && $_POST['submit'] != "" ) { $name = $_POST["name"]; $address = $_POST["address"]; $tel = $_POST["tel"]; $fax = $_POST["fax"]; $email = $_POST["email"]; $website = $_POST["website"]; $type = $_POST["type"]; try { $sql="INSERT INTO bk_customer (id,name,address,tel,fax,email,type,website) VALUES ('$name','$address','$tel','$fax','$email','$website','$type')"; $result = mysqli_query($con,$sql) ; exit(); } catch (Exception $ex) { echo $e->getMessage() . "\n"; file_put_contents('PDOErrors.txt', $e->getMessage(), FILE_APPEND); exit(); } } mysqli_close($con); ?> Link to comment https://forums.phpfreaks.com/topic/287577-problem-in-insert-into-mysql-table/ Share on other sites More sharing options...
ginerjm Posted April 7, 2014 Share Posted April 7, 2014 How do you know you don't have an error? Do you have php errors enabled? You aren't checking that the result of your query is valid either. You exit without showing any of your results, not even an acknowledgement that it MAY have worked. With that said - your query is bad. Link to comment https://forums.phpfreaks.com/topic/287577-problem-in-insert-into-mysql-table/#findComment-1475226 Share on other sites More sharing options...
maideen Posted April 7, 2014 Author Share Posted April 7, 2014 hi Thanks for your comment I have solved, just remove the id. Works fine. Thank you maideen Link to comment https://forums.phpfreaks.com/topic/287577-problem-in-insert-into-mysql-table/#findComment-1475249 Share on other sites More sharing options...
ginerjm Posted April 7, 2014 Share Posted April 7, 2014 Happy that you have solved this problem. Something you should consider in future efforts. The following line: asdf $result = mysqli_query($con,$sql); holds the results of your query. IF it ran successfully. When it doesn't it contains 'false' - which you should always test for in order to be sure that you actually have results to play with. Simply add: $result = mysqli_query($con,$sql); if (!$result) { echo "Query did not run - error is ---"; ( here you should show an error message from mysqli and decide what you want to do from this point on.) } Link to comment https://forums.phpfreaks.com/topic/287577-problem-in-insert-into-mysql-table/#findComment-1475250 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.