开发者

how to set a status

here i've a problem where i want to set the status whether it is approved or reject.. the condition are if admin select the registration number and driver name, that means the status is approve otherwise, if admin fill up the reason,开发者_Python百科 that means the request is reject.. here is the code to set status

if ($reason =='null'){

                $query2 = "UPDATE usage SET status ='APPROVED' WHERE '$bookingno'=bookingno";
                $result2 = @mysql_query($query2);
    }
    elseif (($regno =='null')&&($d_name =='null')) {

                $query3 = "UPDATE usage SET status ='REJECT' WHERE '$bookingno'=bookingno";
                $result3 = @mysql_query($query3);
    }

when i save the data, the status field are not updates..


Two things:

(1) 'null' (with quotation marks) is a string. You probably just want null (and an identity rather than an equality check) - or, better yet, use is_null(), isset() or empty() (whichever is more appropriate in your case).

(2) If your status field is an ENUM() (which it ought to be), make sure you've got capitalisation right. Normally it shouldn't matter, but if your table is set to any sort of binary character encoding (*_bin Collation), it will.


You have your where clause formatted incorrectly, it seems. Change this:

$query2 = "UPDATE usage SET status ='APPROVED' WHERE '$bookingno'=bookingno";

to this:

$query2 = "UPDATE usage SET status ='APPROVED' WHERE bookingno='$bookingno'";

(for both $query2 and $query3).

See if that doesn't fix it.


a very easy way to solve this would be to log the query string as it's been created

if ($reason =='null'){

    $query2 = "UPDATE usage SET status ='APPROVED' WHERE '$bookingno'=bookingno";
    $result2 = @mysql_query($query2);
    error_log($query2);

}
elseif (($regno =='null')&&($d_name =='null')) {

            $query3 = "UPDATE usage SET status ='REJECT' WHERE '$bookingno'=bookingno";
            $result3 = @mysql_query($query3);
            error_log($query3);
}

Then go check the query string that was created in the php error log file, if the query does not work then run the query against your database natively or phpmyadmin if you are using mysql....see if you get an errors. sometimes you will find that your varibales do not populate as intented and this will be revealed by the log file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜