Hello there,
I've recently stumbled upon something strange with some PHP\SQL where a DELETE statement only deletes a record on the
id column or by directly plugging in the conditional value instead of using a variable. Which should not be so. Here is the code that I was working with:
$ClientDeleteID = $_GET['Cid'];
mysql_select_db($database, $connection);
$deleteSQL = "DELETE FROM `client` WHERE `client_id` = '$ClientDeleteID' ";
$Result1 = mysql_query($deleteSQL, $connection) or die(mysql_error());
- $ClientDeleteID = $_GET['Cid'];
-
- mysql_select_db($database, $connection);
- $deleteSQL = "DELETE FROM `client` WHERE `client_id` = '$ClientDeleteID' ";
- $Result1 = mysql_query($deleteSQL, $connection) or die(mysql_error());
client_id is actually the users' name, containing both letters and numbers. I have echoed
$ClientDeleteID and compared its result to that stored in the database; No problems there the values are the same, but the statement still does not delete the row where
`client_id` = '$ClientDeleteID'. If I change the code to only delete by the key
id column, it deletes the row. I have also tried plugging in the value of
$_GET['Cid'] directly into the query instead of the variable
$ClientDeleteID and the row then deletes. Just wondering why it will not delete with the the variable
$ClientDeleteID.
By the way, I've tried changing the data type of the column
client_id from vachar to text and the like, to see if there was a conflict, renamed
$ClientDeleteID to something short like
$cid (not that it should matter), still the row will not be deleted. Where might I be going wrong?
Thanks.
theBruney