Your code doesnât seem to be malformed, so I imagine the if statement is being evaluated correctly.
Itâs possible to place restrictions on DB column types, along with default values and whether that field is allowed to be null. Iâll assume youâre using a MySQL database here, in which case you can run the following query to get some information about your table schema:
DESCRIBE halbForm;
The resulting output will give you information regarding the column types and rules regarding records in that table. That might lead you to the answer to your question about empty strings. FWIW, it is perfectly acceptable to store an empty string a database field.
Looking at the code though, I wonder which path is being executed. When you are having the issue with the record not being saved to the database, are you catching your PDOException and echoing out your error message on your error.html.php page? If this is the case, you could get some more helpful information from the PDOException:
catch (PDOException $e)
{
print_r($e); // Add this line
$error = 'Error inserting into halbForm';
include 'error.html.php';
exit();
}
Warning - Shameless plug for my github project following:
You may also want to perform some more analysis on your query, which can be troublesome using PDOâs prepared statements. If youâve exhausted your other troubleshooting steps and would like to see an example of what the query being executed actually looks like, you can try using this project to simulate that query:
I just changed that column to allow it to be NULL and I am sure that that is it. But I have been trying to get the form to do other things and at the moment it isnât working and wonât be until I fix that and so i canât actually see just now if it is working or not. But I am sure that that was the problem and will post again as soon as i know.
Thanks for you help.
Shane
1: Advise against using âandâ as opposed to &&. [Reference][1]. While it doesnt interfere with you here, I could in the future.
2: Dont give your form items different names in this way. Instead label them as name=âresultâ and then handle them on a per-row basis.
3: Is âsessionâ a checkbox? If itâs a text box, it will always be âsetâ even if empty.
4. Do all of this:
Yes I know I should do it with an array, just seemed simpler the way I did it.
Here âsessionâ comes from a selection menu, but next I will be using a checkbox menu for session in a search form section of the site. So this is good advice.