In a script I receive a variable value with GET request and I have to explode it by a delimiter but sometimes part of the string is empty. How do I declare that in the INSERT query to insert NULL if string is empty?
$statement = $db->prepare('insert into _table (column1, column2, etc) values values (?, ?, etc)
if (isset($_GET['var']) || isset($_GET['var1'])) {
$pieces=explode("delimeter", $var);
// $data = array($pieces[0], pieces[1], etc...);
} else {
// other things to do with // $data = array(...);
}
$statement->execute($data);
Sometimes it happens that the value of $pieces[0], $pieces[1], etc is "" (quote excluded, just for reference), or so to say empty. How do I make it insert NULL in the database if any of the exploded pieces are empty? Not really sure where and how to declare the !empty check because of the isset. Current code enters blanks in the table rows instead of NULL.
Aucun commentaire:
Enregistrer un commentaire