Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 31

Thread: whats wrong with this sql statement

  1. #11
    Join Date
    Mar 2003
    Posts
    492
    Rep Power
    0

    Default

    Quote Originally Posted by leocrawf View Post
    WHEN I REMOVE THE COMMAS I GET THIS ERROR:
    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/www/SOMEDOMAIN.COM 17
    success=0
    I'm not too sure UPDATES return rows. I've only seen this feature in PostgreSQL 8.2 (UPDATE RETURNING). So you might want to check that bit of code again.

  2. #12
    Join Date
    Apr 2003
    Posts
    13,269
    Rep Power
    34

    Default

    Quote Originally Posted by Blunty Killer View Post
    I'm not too sure UPDATES return rows. I've only seen this feature in PostgreSQL 8.2 (UPDATE RETURNING). So you might want to check that bit of code again.
    Yes it does.
    UPDATE returns the number of rows that were actually changed. The mysql_info() C API function returns the number of rows that were matched and updated and the number of warnings that occurred during the UPDATE.
    Taken from here: http://dev.mysql.com/doc/refman/5.0/en/update.html

    Quote Originally Posted by leocrawf View Post
    WHEN I REMOVE THE COMMAS I GET THIS ERROR:
    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/www/SOMEDOMAIN.COM 17
    success=0
    mysql_num_rows is only used for commands like SELECT or SHOW. Use mysql_affected_rows() instead.

    See here: http://www.php.net/mysql_num_rows
    And here: http://www.php.net/manual/en/functio...ected-rows.php

    So that line would change from:
    PHP Code:
    $num_result mysql_num_rows($result); 
    to
    PHP Code:
    $num_result mysql_affected_rows(); 
    But I'm no php expert.

    Let me know if it works.
    "The best software is the one that fits your needs." - A_A

    Virus free since: date unknown
    Anti-virus free since: August 2008

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

    Default

    why y'all goin round the problem.
    youngster, your LIMIT is the problem, the only reason you should try to do this is if there are more than one row in the table with ipc = 123 (etc.). by the looks of it you trying to make the update affect only one row.
    the way to do that is make ipc a (primary) key of the table. if thats already done, then theres no need for LIMIT.
    lay that aside, LIMIT as i have come to know it is used to control output of SELECT queries. so your query is flawed by having LIMIT in an UPDATE query, JUST REMOVE IT.

    Code:
    $query = "UPDATE ipcinfo SET active ='$active' WHERE ipc ='$ipc'";
    also theres quotes around your '$ipc' which indicates its character data, remove that if its numeric.
    Last edited by icymint3; Dec 12, 2006 at 09:22 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

  4. #14
    Join Date
    Apr 2003
    Posts
    13,269
    Rep Power
    34

    Default

    Quote Originally Posted by icymint3 View Post
    why y'all goin round the problem.
    Cause we enjoy confusing others until you can come around and help us out. The real question is though, what took you so long?
    "The best software is the one that fits your needs." - A_A

    Virus free since: date unknown
    Anti-virus free since: August 2008

  5. #15
    Join Date
    May 2004
    Posts
    530
    Rep Power
    0

    Default

    thanks very much you all . will try them all and hopefully something will work. Sometimes the simplest of things take the longest to do.
    "...men are that they might have joy."
    Nephi

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

    Default

    Well you all i have tried what you all said by using the id instead of ipc and $num_result = mysql_affected_rows() instaed of $num_result = mysql_num_rows($result). However this is what turned up:
    "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 = 4' at line 1"

    here is the full block of code:

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

    // This is the SQL statement that will update the appropriate table in the database
    $query "UPDATE ipcinfo SET active = $active, WHERE id = $id";
    if (!
    $result mysql_query($query)) {
      die(
    mysql_error());
    }
    $num_result mysql_affected_rows($result);
    /* This just gets the number of rows in the Query - It's just a check to see if the ipc 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
    "active=$active";
       }
      else
      {
        echo( 
    "success=0" );
      }

      
    // Clean up
      
    mysql_close($dblink);
    ?>
    Last edited by Arch_Angel; Dec 13, 2006 at 09:30 AM. Reason: added PHP code formatting
    "...men are that they might have joy."
    Nephi

  7. #17
    Join Date
    Apr 2003
    Posts
    13,269
    Rep Power
    34

    Default

    Quote Originally Posted by leocrawf View Post
    Well you all i have tried what you all said by using the id instead of ipc and $num_result = mysql_affected_rows() instaed of $num_result = mysql_num_rows($result). However this is what turned up:
    "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 = 4' at line 1"
    The same comma after the $active. You still haven't removed it.
    "The best software is the one that fits your needs." - A_A

    Virus free since: date unknown
    Anti-virus free since: August 2008

  8. #18
    Join Date
    May 2004
    Posts
    530
    Rep Power
    0

    Default

    ok i am going to try it again.
    "...men are that they might have joy."
    Nephi

  9. #19
    Join Date
    May 2004
    Posts
    530
    Rep Power
    0

    Default

    i am now getting this error:

    Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in /home/www/someurl on line 12
    success=0

    WHY SOMETHING SO SIMPLE IS SO HARD TO DO.
    Last edited by leocrawf; Dec 13, 2006 at 09:52 AM.
    "...men are that they might have joy."
    Nephi

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

    Default

    Ok this is what i discovered. The field is actually updating now(thank goodness) but i am still getting the error.
    Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in /home/www/mobilenoni.com/someurl on line 12
    success=0


    this is line 12:$num_result = mysql_affected_rows($result);
    "...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
  •