On my page I have a few textboxes and two of those, first name and last name, are not required. If nothing is entered in one or both of those fields I need to insert NULL as nothing rather than NULL as a string value. Currently it is entering them as string values. What do I need to do so it inserts NULL values instead of a string?
PHP Code
<?php
// SQL connection and other variables...
if (!empty($_POST['firstname'])) {
$firstname = $_POST['firstname'];
} else {
$firstname = 'NULL';
}
if (!empty($_POST['lastname'])) {
$lastname = $_POST['lastname'];
} else {
$lastname = 'NULL';
}
$sp = "exec sp_test_proc '$street1', '$street2', '$firstname', '$lastname'";
$res = odbc_exec($conn, $sp);
?>
If I pass in NULL instead of the variable for either of the parameters it works fine. Not sure what is causing the issue by using a variable.