Results 1 to 9 of 9

Thread: SQL Query Problem

  1. #1

    Thread Starter
    Hyperactive Member AvisSoft's Avatar
    Join Date
    Sep 2002
    Location
    Chandigarh
    Posts
    459

    Angry 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

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    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()); 
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Hyperactive Member AvisSoft's Avatar
    Join Date
    Sep 2002
    Location
    Chandigarh
    Posts
    459

    Angry 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

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    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.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5

    Thread Starter
    Hyperactive Member AvisSoft's Avatar
    Join Date
    Sep 2002
    Location
    Chandigarh
    Posts
    459

    Talking 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

  6. #6
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: SQL Query Problem

    Quote 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?
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  7. #7
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802

    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

  8. #8

    Thread Starter
    Hyperactive Member AvisSoft's Avatar
    Join Date
    Sep 2002
    Location
    Chandigarh
    Posts
    459

    Angry Re: SQL Query Problem

    Hi!

    I am using 4.0.18...its very weird.

    Thanks!
    Tapan Bhanot,
    CEO, Avis Software.
    Website: www.avissoftware.com

  9. #9
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: SQL Query Problem

    I will try to find out why and post here when I do.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width