I have a page that imports fields from a csv file and imports them into my database. Before the fields can be imported into my database I need to separate the name field into two separate values (first name & last name). I do it like so:
$name = $order[5];
$fname = sqlSafe(trim(substr($name, 0, strrpos($name, " "))));`
$lname = sqlSafe(trim(substr($name, strrpos($name, " "))));`
This seems to work reasonably well, but sometimes the name field has been left partially complete (they've entered just their first name or last name for example). This results $fname being blank and mysql won't allow me to set a default value for a BLOB/TEXT column.
To solve this I have tried a couple of if
statements including:
if (!$fname) {$fname = "(blank)";}
if ($fname = "") {$fname = "(blank)";}
if ($fname = NULL) {$fname = "(blank)";}
None of which seem to catch it. Where am I going wrong?