tags:

views:

79

answers:

3

hello guys..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, 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..

A: 

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.

inkedmn
why would the order of column/value matter in the `WHERE` clause (quick tests prove it doesn't make a difference at least in MySql 5)
Marek Karbarz
@inkedmn: it still does'nt work@marek: u mean?i not understand what u have said :-)
@ejah85 - my comment was in response to inkedmn's answer. In MySql it doesn't seem to matter if you write `'$bookingno'=bookingno` (value first then column name) or `bookingno='$bookingno'` (column first then value) in the `where` clause
Marek Karbarz
+1  A: 

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.

pinkgothic
(1) or even is_null http://uk2.php.net/manual/en/function.is-null.php
Matt Ellen
Same thing as an identity-check against null, but, good catch! I'll edit that in. Thank you!
pinkgothic
A: 

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.

Ronald Conco