Please tell me how to send a null string to be inserted in a MySQL database. If I do something like: $string = null; mysql_query("insert ignore into table(field) values($string)");
This will result in the following SQL query:
insert ignore into table(field) values()
If you output a NULL-String then it's just an empty string. That's why you get an error. You have to insert the string NULL into your SQL statement. But I'm sure you don't want to hardcode this. You want to insert a real string if it is set and you want to insert NULL if the string is not set, or not? Then you may try this:
mysql_query(sprintf("insert ignore into table (field) values (%s)", is_null($string) ? "NULL" : "'$string'"));
Do I need to addslashes(), or what else?
If the string comes from user input and PHP is not escaping it automatically then you want to use this.
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php