Jump to content

Setting Value Of Form Post To Null??


twilitegxa

Recommended Posts

Is there a way to insert 'Null' into a field if a form's posted values has been left empty? I want to allow a user to have the option of filling to a form field or not, but I would like to insert Null instead of a blank space into my form. Is this possible? I have a page that displays the optional field values, and if they are null, I have it set to not show.

Link to comment
https://forums.phpfreaks.com/topic/196760-setting-value-of-form-post-to-null/
Share on other sites

on the php page before you INSERT the form data into the db you would want something like:

 

$field1=$_POST['formfield1'];

 

if($field1 == ""){

$field1 = NULL;

}

 

Then when you have your insert:

 

INSERT (DBfield1) VALUES ($field1)

 

it should work for you. I'm not sure if you need to actually have $field1 equal to NULL or "NULL" since NULL is a php var. You may want to play with it.

 

Hope that helps

-K.candiotti

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.