I'm trying to insert NULL into the mySQL databse with PHP.
I've got:
$myVariable=$_POST[inputfield];
if(!is_numeric($myVariable) || $myVariable==0){
$myVariable=NULL;
}
My database field is decimal, and IS NULL has been set. It keeps reverting to 0.00 if input is left blank. How do I set NULL if left blank, so I can call a php if NULL function?
Edit Calling if NULL in decimal is not correct?
<? if ($debit==NULL || $debit=="0.00") {echo 'Awaiting Cost';}
elseif ($debit != NULL || $debit!="0.00") { echo "£$debit";}?>
This displays my message correctly, so if if NULL is useless for a decimal i'll just leave 0.00. Is this hacky?
SQL structure for those who asked:
`myTableField` decimal(10,2) default NULL,
Try it on the SQL side:
try:
.
if your code is:
the MySQL got the string:
it's like using :
If you are composing an SQL statement by appending the value of the
$myVariable
variable, then you should look if it'sNULL
or not and modify the SQL statement accordingly.For example, if your code is something like:
then you should change it to something like:
you can filter field's data in MySQL itself, using a TRIGGER: