Jump to content

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]
Link to comment
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--]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.