Jump to content

Archived

This topic is now archived and is closed to further replies.

Brandon Jaeger

Query help

Recommended Posts

It says that I have an error in my SQL syntax and the query was empty and such. Here's the code:
[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;
    }[/code]

Share this post


Link to post
Share on other sites
[code] <?php
...
for($i = 0; $i < 9; $i++)
      mysql_query($query[i]) or die(mysql_error() . ". Report this to blah@blah.com");
...
?>[/code]

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--]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.