Skip to content
Advertisement

SQL not Inserting using PHP

I have the following code sending data from a form to an SQL database:

JavaScript

My database table is structured as with studentID being a primary key auto incrementing and all fields apart from dob as text (dob is set as datetime)

The form which is sending the data looks like this:

JavaScript

I’m not getting a PDO error but the data is not inserting in to the table. I’m thinking that it might be something to do with the date picker not matching with the data type in SQL but I’m not sure. Any ideas?

Advertisement

Answer

Get MySQL Errors in PHP

You can know if the MySQLi statement succeeded by printing the results of $statement->execute(). To quote the POD…

Return Values

Returns TRUE on success or FALSE on failure. (Source: PHP.net)

If it returns TRUE, then maybe there is a different problem going on than the statement failing.

You can also see the results of MySQL statement with error() and errno(), from the MySQLi package in PHP. You don’t list it in your code, but you must have defined $dbconn in a way like this…

JavaScript

After executing with $stmtUsr2 -> execute();, try running this code…

JavaScript

Your Specific Case

Change your datepicker’s format to match MySQL’s insert format.

JavaScript

More Help

I have another answer on getting more debug info here: debug_print_backtrace() to String for log-file.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement