Had a need to send null values through PHP today. Finally figured it out. If I had the following query
$qry = INSERT INTO company_tb (cname,address,city) values (‘$name’,'$address’,$city)
and $city was my variable to pass the city value, then I would do the following
if ($city==”") //if $city is empty
$city = “NULL”; //set it as NULL
else $city = “‘” . $city . “‘”; //else set it as the city name plus single quotes around it. So if $city had Karachi, $city would become ‘Karachi’
So the query would become INSERT INTO company_tb (cname,address,city) values (‘Aqueeb’,'test address’,'Karachi’) if there was a city value otherwise it would become INSERT INTO company_tb (cname,address,city) values (‘Aqueeb’,'test address’,NULL)
Hope this helps someone! If you have any questions please feel free to ask them!
Tags: PHP MySql NULL
Greatings, Interesting, I`ll quote it on my site later.
Robor
achnid.com – da best. Keep it going!
SonyaSunny