
And if I put a number instead of the default value that is not already in the table it works, so I really don't understand where the problem is.ĮDIT: The table structure on the database:ĮDIT 2: I tried to delete the table and create it again, and now it works with the NULL thing. In order to avoid SQL injections and other vulnerabilities that come with the integration of variables straight in the SQL statement (not a huge problem in this case, but it's good practice), you can use PDO with prepared statements. I search similar questions here in stackoverflow, and I try to use DEFAULT or NULL, but it doesn't work.


The 'insert.php' file connects to the MySQL database server, retrieves forms fields using the PHP REQUEST variables and finally execute the insert query to add the. When a user clicks the submit button of the add record HTML form, in the example above, the form data is sent to 'insert.php' file. VALUES (DEFAULT, '$nome', '$cognome', '$username', '$password', '$nTelefono', '$email')" Step 2: Retrieving and Inserting the Form Data. You don't need echo inside the query echo POST 'fname', you just pass your POST value. Ignore anyone who posts a solution that works with inputting POST directly into the query.

Use prepared statements This rule covers 99 of queries and your query in particular. Been reading through all similar questions here as well and tried with no luck. The rules of adding a PHP variable inside of any MySQL statement are plain and simple: 1. What I'm actually trying to do is insert a row with: Use mysqli prepare and bind the variables. I have spent two days trying to figure out why this statement wouldn't insert those data into my database.
