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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.