Hi,
Here's my question: How do I pass a NULL value in a variable to a
MySQL DB?
Here's an overview of my problem: I have a PHP page that processes
code, then inserts the code into a database. Very straightforward .
But, some NULL values are being inserted as a blank space, or the
string "NULL" instead of a true NULL.
Below is the db insert...
$db = mysql_connect ("localhost" , "user name", "password") ;
mysql_select_db ("database name");
$query = "insert into customers (customer_id, application_dat e,
application_tim e, referring_web_s ite, keywords, first_name, last_name,
email, address, city, state, zip, home_phone, business_phone,
best_time_to_ca ll)
values ('', '$appDate', '$appTime', '$Campaign', '$kw', '$fFirstName',
'$fLastName', '$fEmail', '$fAddress', '', '$fState', '$fZip',
'$fHomePhoneCom bined', '$fBusinessPhon eCombined', '$fBestTime')";
$result = mysql_query($qu ery) or die('Failed because:
'.mysql_error() );
An example of one of the fields that may need to be null is
$fBusinessPhone Combined. If the user does not enter a telephone number
into the business phone field, then I would like to insert a NULL
value into the database. I tried the following code (at different
times) to make the variable pass a null value, but these don't work. I
either get a blank entry, or the string "NULL" inserted into the DB:
if ($fBusinessPhon e1 == ""){
$fBusinessPhone Combined = '';
}
if ($fBusinessPhon e1 == ""){
$fBusinessPhone Combined = NULL;
}
if ($fBusinessPhon e1 == ""){
$fBusinessPhone Combined = 'NULL';
}
HELP! :-)
Thanks in advance,
- Mark
Here's my question: How do I pass a NULL value in a variable to a
MySQL DB?
Here's an overview of my problem: I have a PHP page that processes
code, then inserts the code into a database. Very straightforward .
But, some NULL values are being inserted as a blank space, or the
string "NULL" instead of a true NULL.
Below is the db insert...
$db = mysql_connect ("localhost" , "user name", "password") ;
mysql_select_db ("database name");
$query = "insert into customers (customer_id, application_dat e,
application_tim e, referring_web_s ite, keywords, first_name, last_name,
email, address, city, state, zip, home_phone, business_phone,
best_time_to_ca ll)
values ('', '$appDate', '$appTime', '$Campaign', '$kw', '$fFirstName',
'$fLastName', '$fEmail', '$fAddress', '', '$fState', '$fZip',
'$fHomePhoneCom bined', '$fBusinessPhon eCombined', '$fBestTime')";
$result = mysql_query($qu ery) or die('Failed because:
'.mysql_error() );
An example of one of the fields that may need to be null is
$fBusinessPhone Combined. If the user does not enter a telephone number
into the business phone field, then I would like to insert a NULL
value into the database. I tried the following code (at different
times) to make the variable pass a null value, but these don't work. I
either get a blank entry, or the string "NULL" inserted into the DB:
if ($fBusinessPhon e1 == ""){
$fBusinessPhone Combined = '';
}
if ($fBusinessPhon e1 == ""){
$fBusinessPhone Combined = NULL;
}
if ($fBusinessPhon e1 == ""){
$fBusinessPhone Combined = 'NULL';
}
HELP! :-)
Thanks in advance,
- Mark
Comment