如果Null不起作用,则为SQL Update文本值

I am trying to make it so that a specific value can only be set once, by making it so that i can only be updated or set if it is equal to null. For some reason, the PHP still echoes success even when the value is equal to something like: "Steve". What am I doing wrong?

PHP:

<?php
$dbhandle = mysql_connect($hostname, $username, $password) 
  or die("Unable to connect to MySQL");

//select a database to work with
$selected = mysql_select_db("???????",$dbhandle) 
  or die("Could not select examples");

if(empty($_POST['OrderID']) || empty($_POST['UserName'])){
            echo 'Failed. Fill out all fields.';
        }
else{
        $sql = mysql_query("SELECT * FROM orders WHERE order_id = '".$_POST['OrderID']."' AND LENGTH(accepter_name)= 0");
        $row = mysql_fetch_row($sql); // get the single row.
        echo $row['accepter_name']; // display the value.    

        if($row['accepter_name']==''){ 
            $sql = mysql_query("UPDATE orders SET accepter_name= '".$_POST['UserName']."' WHERE order_id='".$_POST['OrderID']."'");
                    echo "Success";   
        }
        else{
        echo "Failed";
         }
}
mysql_close($dbhandle);
?>

When i check on the database, the accepter name value is changed.

查看全部
dtrn74832
dtrn74832
2014/09/30 08:11
  • php
  • sql
  • 点赞
  • 收藏
  • 回答
    私信

2个回复