Is it possible to have a HTML SELECT/OPTION value as NULL using PHP?

后端 未结 5 1204
Happy的楠姐
Happy的楠姐 2020-12-29 19:42

The following is a snippet from my HTML form which pulls the options from the table rows accordingly.

What I want to do is have the first option value to be NULL so

5条回答
  •  孤城傲影
    2020-12-29 20:04

    that's why Idon't like NULL values in the database at all.
    I hope you are having it for a reason.

    if ($_POST['location_id'] === '') {
      $location_id = 'NULL';
    } else {
      $location_id = "'".$_POST['location_id']."'";
    }
    $notes = mysql_real_escape_string($_POST['notes']);
    $ipid  = mysql_real_escape_string($_POST['ipid']);
    
    $sql="UPDATE addresses 
        SET notes='$notes', location_id=$location_id
        WHERE ipid = '$ipid'";
    
    echo $sql; //to see different queries this code produces
    // and difference between NULL and 'NULL' in the query
    

提交回复
热议问题