0

I searched almost whole internet, but could not find something similar, yet my question looks so simple.

I have a php code like so:

$id = 1;    
if (!isset($_POST['port1'])) {
        $port1 = null;
    }

... which simply checks if submitted value is empty or not, if it is empty, then variable $port1 = null;

then, further in the code, I need to insert this value/update it in the database

$sql_update = ("UPDATE names_10 SET `digName1`=$port1 WHERE `device_id`='$id'");

...which should set the "digname1" to null. but it won't! I tried every combination, every type of quotes, but every time I got UPDATE error..

any ideas?

David Stančík
  • 340
  • 6
  • 23

1 Answers1

1

Try this:

$id = 1;    
if (!isset($_POST['port1'])) {
        $port1 = "NULL";
}

$sql_update = ("UPDATE names_10 SET `digName1`= $port1 WHERE `device_id`='$id'");

I would rather suggest you to use PDO when you plan to bind something like this. There are a lot of benefits using PDO that would amaze you!

Satish Saini
  • 2,880
  • 3
  • 24
  • 38