I have a html form that sends POST data to php file.
In php I’m making a query to mysql database. In database I have int column that accept null.
The problem is when web form field is empty, I want to save null to database.
I tried to make check before building the query
if (empty($licence))
$sql_query.="null,r1=";
else $sql_query.="'".$_POST["licence"]."',r1=";
It’s working. But if user write 0 in the form field, in database will be saved null, which is wrong. If user entered 0, I want to save 0, but if the field is empty I want to save null. How to fix this??
The problem is that if field is empty, 0 will be send as post data…
empty() function(PHP Manual)
Returns FALSE if var exists and has a non-empty, non-zero value. Otherwise returns TRUE.
The following things are considered to be empty:
In your case, use:
instead