Re: delete a record not working

From: Date: Thu, 17 Jun 2004 11:59:08 +0000
Subject: Re: delete a record not working
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-34825@lists.php.net to get a copy of this message
hi, if the column type of id is varchar or char, u need to put '' around id. ur query should look like mysql_query("DELETE FROM open_trades WHERE id= '".$id."'"); Note that your can leave any space between " and ' if u do have a space between them, ur query will look like mysql_query("DELETE FROM open_trades WHERE id= ' valueofID'"); instead of mysql_query("DELETE FROM open_trades WHERE id= 'valueofID'"); and the first query will not return any result becuase of that space Justin wrote:
Hello, I have a simple script to retrieve and then delete a selected script, but it does not work. When I hit the button I get: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'id' at line 11064" Any help would be appreciated. Thanks <form action="<? echo $PHP_SELF ?>" method="post"> <?php mysql_pconnect("localhost","root","password"); mysql_select_db("options"); $result = mysql_query("select * from open_trades"); while ($row = mysql_fetch_array($result)) {
    print "<tr><td>";
    print "<INPUT TYPE='RADIO' NAME='id' VALUE='id'>";
    print "</td><td>";
    print $row["id"];
    print "</td><td>";
    print $row["open_date"];
    print "</td><td>";
    print $row["short_long_trade"];
    print "</td><td>";
    print $row["expiry"];
    print "</td></tr>\n";
} print "</table>\n"; ?> <input type="submit" name="submit" value="close"></form> <?php if($submit)
                 {
                  mysql_query("DELETE FROM open_trades WHERE id=$id");
                  echo "Thank you! Information updated.";
                  echo mysql_error();
                  echo mysql_errno();
                  }
?>


« previous php.db (#34825) next »