Forum Moderators: coopster
$percent_non_smoking=$HTTP_POST_VARS['percent_non_smoking'];
if (!$percent_non_smoking) $percent_non_smoking = 'NULL';
echo 'Percent Non-Smoking: '.$percent_non_smoking.'.<br>';
If the user enters nothing in the html form as "percent non smoking" then I want to enter NULL into MySQL. However, if the user enters '0' in the form, then I want to enter '0' into MySQL.
However, it seems that if the user enters 0, PHP thinks this is nothing, and sets it to NULL.
Any suggestions would be appreciated.
Rgds
$percent_non_smoking=$HTTP_POST_VARS['percent_non_smoking'];
if (!$percent_non_smoking) $percent_non_smoking = 'NULL';
echo 'Percent Non-Smoking: '.$percent_non_smoking.'.<br>';
that code is exactly designed to do what you are complaining about - that's just about all it does :-(
Set the default value in the html form to something - for example a non-breaking space.
$percent_non_smoking=$HTTP_POST_VARS['percent_non_smoking'];
if ($percent_non_smoking==" ") $percent_non_smoking = 'NULL';
echo 'Percent Non-Smoking: '.$percent_non_smoking.'.<br>';
That will fix it.