Query not working from code but works from manager on godaddy

Discussion in 'MySQL' started by Sleeping Troll, Aug 16, 2008.

  1. #1
    This is the code:

    <?php
    $conn = mysql_connect("xxx","xxx","xxx"); 
    mysql_select_db("xxx",$conn);
    if ($_COOKIE["user"])
    	{
    		$ID=$_COOKIE["user"];
    		$SQL = "Select * From ClientData Where ID = ".$ID;
    		$result = mysql_query($SQL);
    		if ($result <> "")
    			{
    				$row = mysql_fetch_row($result);
    				$Msg = "Welcome back $row[1]!";
    				$SQL = "Update Tracking Set Return = Return + 1";
    				if ($row[1])
    					{
    						$SQL = "Update Tracking Set Client = Client + 1";
    					}
    			}
    	}
    else
    	{
    
    		$ID = mt_rand(0,9999999999);
    		setcookie("Brag_Flag_user",$ID, time()+(60*60*24*30));
    		$SQL = "Insert Into ClientData (ID) Values ('".$ID."')";
    		mysql_query($SQL);
    		$Msg = "Welcome to";
    		$SQL = "Update Tracking Set First = First + 1";
    	}
    [COLOR="Red"]
    echo $SQL;
    mysql_query($SQL);
    [/COLOR]
    ?>
    
    Code (markup):
    The SQL statement works fine in mysql manager (cut and paste "echo" from page) but not in code!
     
    Sleeping Troll, Aug 16, 2008 IP
  2. Sleeping Troll

    Sleeping Troll Peon

    Messages:
    217
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Update Tracking Set Return = Return + 1 This is where error is, how should I increment value of "Return" column?
     
    Sleeping Troll, Aug 16, 2008 IP
  3. cont911

    cont911 Peon

    Messages:
    50
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Return is a reserved word in mysql.
    Use escaping (`Return`) or rename the field.
     
    cont911, Aug 19, 2008 IP
  4. imphpguru

    imphpguru Active Member

    Messages:
    439
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #4
    cont911 is right. There are a set of mysql reserved keywords. The query you have written, is something of this kind

    UPDATE Tracking set UPDATE = UPDATE + 1.


    Just imagine this. This looks so foolish. What you have done is something like this. Just google "Mysql reserved keywords" and you will know the reserved keywords for mysql.
     
    imphpguru, Aug 19, 2008 IP