PHP $_POST check if empty

Status
Not open for further replies.

Skythrust

Member
Jul 9, 2019
133
7
Hi All,

I am looking for a thing to check if the post field is filled in.

Like when I have a firstname, middlename and lastname and I insert just the first and lastname normally in SQLSRV he is set this to a NULL value.
Now he add some none data which is a blank colomn in SQLSRV

So I was assuming that I can easily fix this with an if else statement but that doesn't work.

For now I have this code

PHP:
if(EMPTY($_POST['middlename']))
    {
        $code = 'SET middlename = NULL';
    }
else
    {
        $code = 'SET middlename =' $_POST['middlename'];
    }

Any idea's how I can realize this?
Thanks!
 

Skythrust

Member
Jul 9, 2019
133
7
After "$code = filter_input(INPUT_POST, 'middlename', FILTER_SANITIZE_STRING);" add "var_dump($code);"

Then test and let us know what the output from that was
The output is: string(0) ""
Post automatically merged:

Any update? :-$
 
Last edited:

Skythrust

Member
Jul 9, 2019
133
7
please explain what exactly do you want. i dont see any problem with the code?
I would like to have a code which filters if there is filled in a middlename, if it is he needs to use this field. Else he needs to fill in the NULL value as default in SQL
Post automatically merged:

Ok.. code works for me like this;

PHP:
if (!empty($_POST['middlename'])) {
    $code = $_POST['middlename'];
} else {
    $code = "NULL";

}

Only the NULL value should be look like this; (red = wrong, green = good)
 
Last edited:
Status
Not open for further replies.

Users who are viewing this thread

Top