Page 1 of 4 123 ... LastLast
Results 1 to 10 of 31

Thread: whats wrong with this sql statement

  1. #1
    Join Date
    May 2004
    Posts
    530
    Rep Power
    0

    Default whats wrong with this sql statement

    i have this simple script that recieve name/value pairs from a flash movie that is suppose to update a feild in a database table. here is it:

    PHP Code:
    <?php
      
    include_once("conn.php");
      
      
    $active = ($_GET["active"]);
      
    $ipc = ($_GET["ipc"]);
      
    $ipc ereg_replace("[^A-Za-z0-9 ]"""$ipc); 
      
    $active ereg_replace("[^A-Za-z0-9 ]"""$active); 



    // This is the SQL statement that will update the appropriate table in the database
    $query "UPDATE ipcinfo SET active ='$active', WHERE ipc ='$ipc' , LIMIT = 1";
    if (!
    $result mysql_query($query)) {
      die(
    mysql_error());
    }
    $num_result mysql_num_rows($result);

     

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

      
    // Clean up
      
    mysql_close($dblink);
    ?>
    when i run it i get this error:

    "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 ipc ='' , LIMIT = 1' at line 1"
    i am not a php/mysql buff so therefore i dont know what is wrong, because it seems ok. Any help is appreciated.
    Last edited by Arch_Angel; Dec 12, 2006 at 10:55 AM. Reason: added PHP code formatting
    "...men are that they might have joy."
    Nephi

  2. #2
    Join Date
    Mar 2003
    Posts
    492
    Rep Power
    0

    Default

    Quote Originally Posted by leocrawf View Post

    // This is the SQL statement that will update the appropriate table in the database
    $query = "UPDATE ipcinfo SET active ='$active', WHERE ipc ='$ipc' , LIMIT = 1";
    I don't think those commas after the SET and WHERE clause are supposed to be there. Try taking them out and see what happens.

  3. #3
    Join Date
    May 2004
    Posts
    530
    Rep Power
    0

    Default

    i tried it and i am still getting that error.
    "...men are that they might have joy."
    Nephi

  4. #4
    Join Date
    Apr 2003
    Posts
    13,270
    Rep Power
    35

    Default

    Can you print the output of the query unto your page?
    I guess something like:
    PHP Code:
    echo $query 
    after you construct your query.
    But I don't know php, so you would have to manage to print it out.
    Should be able to determine from the query why the server doesn't like it.
    "The best software is the one that fits your needs." - A_A

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

  5. #5
    Join Date
    Mar 2003
    Posts
    492
    Rep Power
    0

    Default

    One last thing, with the commas out, remove the '=' after LIMIT. SQL usually take those operators without the equal sign. Ex, ORDER BY field, LIMIT no, OFFSET no.

    Taken from MySQL SELECT Syntax

    SELECT
    [ALL | DISTINCT | DISTINCTROW ]
    [HIGH_PRIORITY]
    [STRAIGHT_JOIN]
    [SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT]
    [SQL_CACHE | SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS]
    select_expr, ...
    [FROM table_references
    [WHERE where_condition]
    [GROUP BY {col_name | expr | position}
    [ASC | DESC], ... [WITH ROLLUP]]
    [HAVING where_condition]
    [ORDER BY {col_name | expr | position}
    [ASC | DESC], ...]
    [LIMIT {[offset,] row_count | row_count OFFSET offset}]
    [PROCEDURE procedure_name(argument_list)]
    [INTO OUTFILE 'file_name' export_options
    | INTO DUMPFILE 'file_name'
    | INTO @var_name [, @var_name]]
    [FOR UPDATE | LOCK IN SHARE MODE]]

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

    Default

    Thanks Agian For Your Help.
    "...men are that they might have joy."
    Nephi

  7. #7
    Join Date
    Apr 2003
    Posts
    13,270
    Rep Power
    35

    Default

    Quote Originally Posted by Blunty Killer View Post
    One last thing, with the commas out, remove the '=' after LIMIT. SQL usually take those operators without the equal sign. Ex, ORDER BY field, LIMIT no, OFFSET no.
    You're right.

    PHP Code:
    $query "UPDATE ipcinfo SET active ='$active' WHERE ipc ='$ipc' LIMIT 1"
    would be the proper query.
    "The best software is the one that fits your needs." - A_A

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

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

    Default

    i am stILL HAVING THE SAME ERROR:
    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 ipc = 123 , LIMIT 1' at line 1
    "...men are that they might have joy."
    Nephi

  9. #9
    Join Date
    Apr 2003
    Posts
    13,270
    Rep Power
    35

    Default

    Quote Originally Posted by leocrawf View Post
    i am stILL HAVING THE SAME ERROR:
    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 ipc = 123 , LIMIT 1' at line 1
    Looks like you still using the commas. Check my previous post.
    "The best software is the one that fits your needs." - A_A

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

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

    Default

    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
    "...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
  •