Forum Moderators: coopster

Message Too Old, No Replies

Zero and Null

         

MilesDependent

12:58 pm on Aug 8, 2003 (gmt 0)

10+ Year Member



I have the following code:

$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

vincevincevince

1:01 pm on Aug 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




$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=="&nbsp;") $percent_non_smoking = 'NULL';
echo 'Percent Non-Smoking: '.$percent_non_smoking.'.<br>';

That will fix it.

MilesDependent

1:11 pm on Aug 8, 2003 (gmt 0)

10+ Year Member



Many thanks for the assistance Vince.

AC