PDA

Click to See Complete Forum and Search --> : SQL Query Problem


AvisSoft
Feb 3rd, 2005, 11:56 AM
Hi!

I am using the following SQL query to update a record. Now the problem i am getting is that its updating all records in the database weather information matches or not, why this is happening ?

// Update account status depending upon the ID & Code
$sql1 = "UPDATE users SET isactive = 'Y' WHERE id = '" . $id . "' AND code = '" . $code . "'";
$result = (mysql_query($sql1)) or die(mysql_error());

The id contains the user id like 1 and the code contains a number like 123456789. So each record has a different id and a different code. But it updates all records and does not cares about the information i provide to it.

Please help!

Thanks!

visualAd
Feb 3rd, 2005, 12:17 PM
I don't see any problems with it. My guess is the values are somehow corrupt from your PHP script. Try adding a debugging echo stement before executing the query and ensure that it is what you are expecting:

// Update account status depending upon the ID & Code
$sql1 = "UPDATE users SET isactive = 'Y' WHERE id = '" . $id .
"' AND code = '" . $code . "'";

echo($sql1);

$result = (mysql_query($sql1)) or die(mysql_error());

AvisSoft
Feb 3rd, 2005, 12:35 PM
Hi!

The query seems to be okay. From the following link:
http://www.efreelancer.net/activate.php?id=2&code=726475905

it created this query:
UPDATE users SET isactive = 'Y' WHERE id = '2' AND code = '726475905'

which seems to be looking okay but its updating all accounts to "Y". Strange!

Help!

visualAd
Feb 3rd, 2005, 12:43 PM
Marke a test script and execute only that query. It should definatly work. If it does then it means another piece of code is setting all the values to 'Y' and you'll need to find out where it is.

AvisSoft
Feb 3rd, 2005, 12:50 PM
Hi visualAd,

LOL i fxied it silly me, the id was a int in the db. LOL. I was putting id in ''. LOL as soon as i removed those it started working :)

Thanks for the help!

Thanks!

visualAd
Feb 3rd, 2005, 04:44 PM
Hi visualAd,

LOL i fxied it silly me, the id was a int in the db. LOL. I was putting id in ''. LOL as soon as i removed those it started working :)

Thanks for the help!

Thanks! That is odd, MySql should cast it to the data type of the column even if you put it in quotes. What version of MySql are you using? :eek:

McCain
Feb 3rd, 2005, 11:49 PM
I get the same weirdness as AvisSoft if I quote my integers. I'm running mySQL 4.0.21

AvisSoft
Feb 4th, 2005, 01:10 AM
Hi!

I am using 4.0.18...its very weird. :eek2:

Thanks!

visualAd
Feb 4th, 2005, 02:12 AM
I will try to find out why and post here when I do. :wave: