I have an insert statement that inserts variables collected from a form POST on the previous page. If the variables from the form are not filled in it fails on insert (presumably because it is inserting an empty string...) I have the dataype set to allow NULL values - how do I insert null values if the field was left empty from the form POST?
$query = "
INSERT INTO songs (
userid,
wavURL,
mp3URL,
genre,
songTitle,
BPM
) VALUES (
'$userid',
'$wavFile',
'$mp3File',
'$genre',
'$songTitle',
'$BPM'
)
";
$result = mysql_query($query);
$songTitle = (empty($songTitle) || null === $songTitle) ? "NULL" : $songTitle;|| null === $songTitlepart is redundant and b) you need to put quotes around$songTitleat the end, it's going to go in an SQL query.$songTitle = (empty($songTitle)) ? "NULL" : "'" . $songTitle . "'";I'm not very familiar withemptyI thought that function just eval for empty$vars = "";