For some reason, i am having difficulty getting this script to function properly

The code is below. The call is

<a href="status.php?s=d&id=<? echo $id; ?>&status=active" 

Processing


<? 
require "connect.php";

if ($s=='d') { 


$sql = "UPDATE `contact_table`  (`status``) VALUES ('$status') WHERE `id` = '$id';";
mysql_query($sql,$db);
if (@mysql_query($sql,$db)) {
echo "Status Changed to $status<br><a href='client.php?id=$id'>Back to Clients</a>";} else { echo"Mysql Error";}

} else {}  ?>

While all the definied variables pass correctly, the script returns mysql error.

Any help would be greatly appreciated.

    Use mysql_error() to obtain more error information and post the error string for people to read.

    http://php.net/manual/en/function.mysql-error.php

    But, you appear to have two `s after the status field name.

    mysql_error would have shown a SQL syntax error, which would of helped you.

      Apart from some horrible code, the only thing I can see is a stray backtick [/B] here
      [code=php](
      status``[/code]

        Although the double single quote was fixed i am still having the same problem. It appears to connect to db

        
        $sql = "UPDATE `contact_table`  (`status``) VALUES ('$status') WHERE `id` = '$id';";
        mysql_query($sql,$db);
        if (@mysql_query($sql,$db)) {
        echo "Status Changed to $status<br><a href='client.php?id=$id'>Back to Clients</a>";} else { echo"Mysql Error";}
        
        

        That if statement produces "Mysql Error" so something appears to be wrong with query

          UPDATE `contact_table`  set `status` = '$status' WHERE `id` = '$id'
          

          You are mixing the syntax for update and insert.

            Thanks, yea originally i had with set, here is the code i just changed it again. Still get the error.

            <? 
            require "connect.php";
            
            
            
            $sql = "UPDATE `contact_table`  set `status` = '$status' WHERE `id` = '$id';";
            mysql_query($sql,$db);
            if (@mysql_query($sql,$db)) {
            echo "Status Changed to $status<br><a href='client.php?id=$id'>Back to Clients</a>";} else { echo"Mysql Error";}
            
               ?>

              Add some error handling

              $sql = "UPDATE `contact_table`  set `status` = '$status' WHERE `id` = '$id'";
              mysql_query($sql,$db) or die(mysql_error()) ; 
              

              echo the content of the variable $sql and test the result interactively.

                Thank you, was something silly and now fixed. Thanks again

                  Write a Reply...