Replace blank $_POST value with NULL
Posted: Sat Aug 04, 2007 2:35 am
Hi.... I have a question and I can't seem to figure it out.
I would consider myself to be between the beginner and intermediate levels of PHP programming. I haven't coded in PHP for a year or two now, except for the past two weeks.
I am pulling data from a HTML form... we'll say the field is called "phone", along with fields 1, 2, etc
I want to insert this data into mysql database people table contact.
After the connection info, I have
Lets say field phone is left empty on the HTML form, and I want empty forms turned into cells with value NULL in mysql.
What type of if statement would I have php run to verify that the length of a field is > 0, and if it isn't, change '$_POST[field]' to NULL
??
Thanks.
I would consider myself to be between the beginner and intermediate levels of PHP programming. I haven't coded in PHP for a year or two now, except for the past two weeks.
I am pulling data from a HTML form... we'll say the field is called "phone", along with fields 1, 2, etc
I want to insert this data into mysql database people table contact.
After the connection info, I have
Code: Select all
$sql="INSERT INTO contact (phone, 1, 2, etc)
VALUES
('$_POST[phone]', '$_POSt[1]', '$_POST[2]', '$_POST[etc]')";What type of if statement would I have php run to verify that the length of a field is > 0, and if it isn't, change '$_POST[field]' to NULL
??
Thanks.