Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 31

Thread: whats wrong with this sql statement

  1. #21
    Join Date
    Dec 2002
    Posts
    500
    Rep Power
    0

    Default

    PHP Code:
    $num_result mysql_affected_rows/*$link*/ ); // $link is optional, and since you only use one database dont pass it 
    $link would be the result of a call to
    PHP Code:
    /* connect to database */
    $link mysql_connect('localhost''mysql_user''mysql_password'); 
    which is probably nestled safely in conn.php
    Last edited by icymint3; Dec 13, 2006 at 02:47 PM.
    Cultured in Aggression and Koding like a Warrior!!
    “Common sense is instinct. Enough of it is genius.” - George Bernard Shaw.
    "The significant problems we face cannot be solved by the same level of thinking that created them." - Albert Einstein

  2. #22
    Join Date
    May 2004
    Posts
    530
    Rep Power
    0

    Default

    "$num_result = mysql_affected_rows()"
    i tried that and still got the same error.
    "...men are that they might have joy."
    Nephi

  3. #23
    Join Date
    Dec 2002
    Posts
    500
    Rep Power
    0

    Default

    PHP Code:
    $num_result mysql_affected_rows$dblink ); 
    Cultured in Aggression and Koding like a Warrior!!
    “Common sense is instinct. Enough of it is genius.” - George Bernard Shaw.
    "The significant problems we face cannot be solved by the same level of thinking that created them." - Albert Einstein

  4. #24
    Join Date
    May 2004
    Posts
    530
    Rep Power
    0

    Default

    tried that but this is the result:
    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 'WHERE id = 2' at line 1
    "...men are that they might have joy."
    Nephi

  5. #25
    Join Date
    Dec 2002
    Posts
    500
    Rep Power
    0

    Default

    post the code youre using, i'm pretty sure you put in the comma again.
    Cultured in Aggression and Koding like a Warrior!!
    “Common sense is instinct. Enough of it is genius.” - George Bernard Shaw.
    "The significant problems we face cannot be solved by the same level of thinking that created them." - Albert Einstein

  6. #26
    Join Date
    May 2004
    Posts
    530
    Rep Power
    0

    Default

    Ran the code agian and this is what i am getting:

    "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/www/someurl/update.php on line 18
    success= 1udate=3"
    However the dtatbase field is updated. Wierd enough. Still would rather it work perfectly though.
    this is the code:

    PHP Code:
    <?php
      
    include_once("conn.php");
      
      
    $udate rawurlencode($_GET["udate"]);
      
    $id rawurlencode($_GET["id"]);

    // This is the SQL statement that will update the appropriate table in the database
    $query "UPDATE ipcinfo SET udate = $udate WHERE id = $id";
    if (!
    $result mysql_query($query)) {
      die(
    mysql_error());
    }
    $num_result mysql_affected_rows($dblink);
    /* This just gets the number of rows in the Query - It's just a check to see if the id exists - If not it echos out an error statement. */

    // If the number of rows is not equal to one then it echos out an error statement 

      
    if ($num_result == 1) {
      if(
    $row mysql_fetch_array($result));
       echo
    "success= 1";
       echo
    "udate=$udate";
       }
      else
      {
        echo( 
    "success=0" );
      }

      
    // Clean up
      
    mysql_close($dblink);
    ?>
    line 18 is this : if($row = mysql_fetch_array($result));

    thanks for any help.
    Last edited by Arch_Angel; Dec 15, 2006 at 10:19 AM. Reason: added PHP code formatting
    "...men are that they might have joy."
    Nephi

  7. #27
    Join Date
    Oct 2005
    Posts
    745
    Rep Power
    0

    Default

    PHP Code:
    if($row mysql_fetch_array($result));
       echo
    "success= 1";
       echo
    "udate=$udate";
       }
      else
      {
        echo( 
    "success=0" );
        
    //add print statement below
        
    print (mysql_error());
      } 
    Try adding a print statement for the last error it should give a more descriptive message as to what the error cause is.
    Last edited by Arch_Angel; Dec 15, 2006 at 03:25 PM. Reason: added PHP code formatting
    3.14159265358979323846264338327950288
    4197169399375105820974944592307816406
    28620899862803482534211706798 pi 101

  8. #28
    Join Date
    Dec 2002
    Posts
    500
    Rep Power
    0

    Default

    thats because your query was an UPDATE and updates do not return results (records) as SELECT does, mysql_fetch_array has no meaning in this context just remove it.

    PHP Code:
    if ($num_result == 1
    {
       if(
    $row mysql_fetch_array($result)); // <-- dont know if you noticed this semicolon here

       
    echo"success= 1";
       echo
    "udate=$udate";
    }
    else
    {
       echo( 
    "success=0" );

    corrected code
    PHP Code:
    <?php
      
    include_once("conn.php");
      
      
    $udate rawurlencode($_GET["udate"]);
      
    $id rawurlencode($_GET["id"]);

      
    // This is the SQL statement that will update the appropriate table in the database
      
    $query "UPDATE ipcinfo SET udate = $udate WHERE id = $id";
      
    $result mysql_query($query) or die(mysql_error());

      
    /* This just gets the number of rows in the Query - It's just a check to see if the id exists - If not it echos out an error statement. */
      
    $num_result mysql_affected_rows($dblink);

      echo 
    "success = $num_result"// show success code ... comment this out
      
    if ($num_result == 1) echo "udate = $udate"// if its a success then  show $udate

      // Clean up
      
    mysql_close($dblink);
    ?>
    Last edited by icymint3; Dec 15, 2006 at 04:40 PM.
    Cultured in Aggression and Koding like a Warrior!!
    “Common sense is instinct. Enough of it is genius.” - George Bernard Shaw.
    "The significant problems we face cannot be solved by the same level of thinking that created them." - Albert Einstein

  9. #29
    Join Date
    Jan 2004
    Posts
    2,011
    Rep Power
    0

    Default

    yeh.. madness that.. update edits records based on ids.. not return as icymint3 pointed out. you cant fetch on a update resource.

  10. #30
    Join Date
    May 2004
    Posts
    530
    Rep Power
    0

    Default

    Thanks you all it worked perfectly. boy that was a difficult trip. Glad to know that closure is here.
    Last edited by leocrawf; Dec 15, 2006 at 11:03 PM.
    "...men are that they might have joy."
    Nephi

Posting Permissions

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