Jump to content
Larry Ullman's Book Forums

Recommended Posts

Hi all,

I have a form that a user fills in to register themselves. I start by making the form variables all FALSE. I then do all the checks, including that none of the variables are still FALSE, and then an INSERT into MySQL.


Now 2 of the form fields are not mandatory, i.e. they can be left blank by the user. So, at this stage they will still be set at FALSE. It won't pass the test so won't INSERT.


I then removed these two variables from the if($blah && $blah etc.) check. It worked and the INSERT worked as well. I then checked the DB table and the 2 non-mandatory fields that had no entry in them appear in the DB as blank fields.


Now to the question (and a typical beginners question with regard to FALSE, NULL, 'blank?'). Are they really 'blank', i.e. empty? When I come to do SELECT queries later on and include those fields am I heading for trouble. What will come back? Would it be better to set the non-mandatory form variables to an empty string, i.e. $blah = ''; if the user did not use them. Then the if... test would work (none would be FALSE) and the DB would get an empty string insrted instead of FALSE. Does it make any difference?





PS. How can I set up this forum so that it emails me all the posts, instead of me having to log in?

Share this post

Link to post
Share on other sites

Good question. The short answer is that a FALSE value in a PHP variable is not the same as a MySQL FALSE or NULL. If you assign the value false to a PHP variable, the resulting database value for that column will depend upon the column's type. It could be 0 for an integer column or an empty string for a character/text column. This would be a problem if later queries would check for that column having a NULL value, because it wouldn't.


What I do in these situations is assign the value NULL to optional fields that the user didn't fill out. You have to be careful with the syntax, though, because the resulting query needs to insert for that column the word NULL without quotes for this to work.


As for getting emails, I believe there's a checkbox for that option when you create the thread.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now