|
-
Feb 3rd, 2005, 12:56 PM
#1
Thread Starter
Hyperactive Member
SQL Query Problem
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 ?
PHP Code:
// 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!
Tapan Bhanot,
CEO, Avis Software.
Website: www.avissoftware.com
-
Feb 3rd, 2005, 01:17 PM
#2
Re: SQL Query Problem
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:
PHP Code:
// 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());
-
Feb 3rd, 2005, 01:35 PM
#3
Thread Starter
Hyperactive Member
Re: SQL Query Problem
Hi!
The query seems to be okay. From the following link:
http://www.efreelancer.net/activate....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!
Tapan Bhanot,
CEO, Avis Software.
Website: www.avissoftware.com
-
Feb 3rd, 2005, 01:43 PM
#4
Re: SQL Query Problem
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.
-
Feb 3rd, 2005, 01:50 PM
#5
Thread Starter
Hyperactive Member
Re: SQL Query Problem
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!
Tapan Bhanot,
CEO, Avis Software.
Website: www.avissoftware.com
-
Feb 3rd, 2005, 05:44 PM
#6
Re: SQL Query Problem
 Originally Posted by AvisSoft
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?
-
Feb 4th, 2005, 12:49 AM
#7
Fanatic Member
Re: SQL Query Problem
I get the same weirdness as AvisSoft if I quote my integers. I'm running mySQL 4.0.21
Never argue with fools, they will only drag you down to their level, and beat you with experience.
Q: How do you tell an experienced hacker from a novice?
A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer
-
Feb 4th, 2005, 02:10 AM
#8
Thread Starter
Hyperactive Member
Re: SQL Query Problem
Hi!
I am using 4.0.18...its very weird.
Thanks!
Tapan Bhanot,
CEO, Avis Software.
Website: www.avissoftware.com
-
Feb 4th, 2005, 03:12 AM
#9
Re: SQL Query Problem
I will try to find out why and post here when I do.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|