Jump to content


Photo

Query help


  • Please log in to reply
2 replies to this topic

#1 Brandon Jaeger

Brandon Jaeger
  • Members
  • PipPipPip
  • Advanced Member
  • 155 posts
  • LocationPA
  • Age:25

Posted 05 May 2006 - 05:46 AM

It says that I have an error in my SQL syntax and the query was empty and such. Here's the code:
    $title = $_POST["title"];
    $location = $_POST["location"];
    $age = $_POST["age"];
    $icq = $_POST["icq"];
    $aim = $_POST["aim"];
    $msn = $_POST["msn"];
    $yahoo = $_POST["yahoo"];
    $web = $_POST["homepage"];
    $coder = $_POST["coder"];

    $query = array();

    $query[0] = sprintf("UPDATE ghw_users SET title='%s' WHERE id='%d'" , quote_smart($title) , $id);
    $query[1] = sprintf("UPDATE ghw_users SET location='%s' WHERE id='%d'" , quote_smart($location) , $id);
    $query[2] = sprintf("UPDATE ghw_users SET age='%s' WHERE id='%d'" , quote_smart($age) , $id);
    $query[3] = sprintf("UPDATE ghw_users SET icq='%s' WHERE id='%d'" , quote_smart($icq) , $id);
    $query[4] = sprintf("UPDATE ghw_users SET aim='%s' WHERE id='%d'" , quote_smart($aim) , $id);
    $query[5] = sprintf("UPDATE ghw_users SET msn='%s' WHERE id='%d'" , quote_smart($msn) , $id);
    $query[6] = sprintf("UPDATE ghw_users SET yahoo='%s' WHERE id='%d'" , quote_smart($yahoo) , $id);
    $query[7] = sprintf("UPDATE ghw_users SET homepage='%s' WHERE id='%d'" , quote_smart($homepage) , $id);
    $query[8] = sprintf("UPDATE ghw_users SET coder='%s' WHERE id='%d'" , quote_smart($coder) , $id);
      
    for($i = 0; $i < 9; $i++)
      mysql_query($query[i]) or die(mysql_error() . ". Report this to blah@blah.com");

    function quote_smart($value)
    {
      if (get_magic_quotes_gpc())
        $value = stripslashes($value);

      if (!is_numeric($value))
        $value = "'" . mysql_real_escape_string($value) . "'";

      return $value;
    }

PHP is my friend (=

#2 jeremywesselman

jeremywesselman
  • Members
  • PipPipPip
  • Advanced Member
  • 154 posts
  • LocationIndependence, KY

Posted 05 May 2006 - 07:59 AM

<?php
...
for($i = 0; $i < 9; $i++)
      mysql_query($query[i]) or die(mysql_error() . ". Report this to blah@blah.com");
...
?>

You need to add a $ in front of the $query[i]. It should be $query[$i].

[!--coloro:#990000--][span style=\"color:#990000\"][!--/coloro--]Jeremy[!--colorc--][/span][!--/colorc--]

#3 Brandon Jaeger

Brandon Jaeger
  • Members
  • PipPipPip
  • Advanced Member
  • 155 posts
  • LocationPA
  • Age:25

Posted 06 May 2006 - 01:40 AM

Oh, duh. I'm used to coding C++ and such.
PHP is my friend (=




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users