Table: productsID varchar, price decimal
Get the input from a form, if price value is not numeric, then it will be NULL.
$productsID=$POST['productsID'];
$price=$POST['prince'];
$productsID=mysql_real_escape_string($productsID);
if (!is_numeric($price))
$price=NULL; //the below sql will have error.
$price="NULL"; //the below sql will be fine
$insert_sql="insert into products (productsID, price) values ('$productsID', $price);
mysql_query($insert_sql);
So my questions are
1) If I want set up the not numeric $price to NULL for my php programming usage, I will use
$price=NULL;
but
2) If I want to insert the NULL value of $price into database
I will need set up
$price="NULL"; //instead of $price=NULL;
Am I right here?
In other words, you cannot just simply insert a null value variable into database, you have to covert it to "NULL" first before insert it?
Thanks!