Results 1 to 3 of 3

Thread: I need a new set of eyes to check this error

  1. #1
    Join Date
    May 2006
    Posts
    4

    Question I need a new set of eyes to check this error

    I've rewritten my insert function with and without mysql_real_escape_string's
    and I still get the same error. Can someone look it over for me? I think it has to do with with the "INSERT INTO table set..." portion of it. I'm referencing the table with $table_select.

    Thanks in advance!

    The error message
    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 ''blank' set first_name='fff', mi='d', last_name='dfdf', suffix='Sr', ' at line 1

    ------
    The code
    $query = sprintf("INSERT INTO '%s' set
    first_name='%s',
    mi='%s',
    last_name='%s',
    suffix='%s',
    address1='%s',
    address2='%s',
    city='%s',
    state='%s',
    zip5='%s',
    zip4='%s',
    state='%s',
    phone_ac='%s',
    phone_ex='%s',
    phone_sub='%s',
    email='%s',
    bio='%s',
    council_num='%s',
    date_created='%s'
    date_updated='%s'",
    mysql_real_escape_string($table_select),
    mysql_real_escape_string($first_name),
    mysql_real_escape_string($mi),
    mysql_real_escape_string($last_name),
    mysql_real_escape_string($suffix),
    mysql_real_escape_string($address1),
    mysql_real_escape_string($address2),
    mysql_real_escape_string($city),
    mysql_real_escape_string($state),
    mysql_real_escape_string($zip5),
    mysql_real_escape_string($zip4),
    mysql_real_escape_string($state),
    mysql_real_escape_string($phone_ac),
    mysql_real_escape_string($phone_ex),
    mysql_real_escape_string($phone_sub),
    mysql_real_escape_string($email),
    mysql_real_escape_string($bio),
    mysql_real_escape_string($council_num),
    mysql_real_escape_string($date),
    mysql_real_escape_string($date));

    $result=mysql_query($query);

  2. #2
    Join Date
    Feb 2006
    Location
    Somewhere where I don't know where I am
    Posts
    2,155

    Default

    Try something like this
    PHP Code:
    $query "INSERT INTO " $table_select "
              (first_name, mi, last_name, suffix, address1, address2, city, state, zip5, zip4, state, phone_ac, phone_ex, phone_sub, email, bio, council_num, date_created, date_updated)
              VALUES 
              ('" 
    $first_name "', '" $mi "', '" $last_name "', '" $suffix "', '" $address1 "', '" $address2 "', '" $city "', '" $state "', '" $zip5 "', '" $zip4 "', '" $state "', '" $phone_ac "', '" $phone_ex "', '" $phone_sub "', '" $email "', '" $bio "', '" $council_num "', '" $date "', '" $date "');";
    $result=mysql_query($query); 
    Sign Up Now!
    Unlimited Storage, Unlimited Transfer, Host Unlimited domain names, 1 Free Domain Name
    BlueHost Features | BlueHost Help Desk | Become a BlueHost Affiliate | BlueHost CEO Blog
    (888) 401-4678 | Create a support ticket

  3. #3
    Join Date
    Feb 2006
    Location
    Canton, GA
    Posts
    162

    Default

    I think your syntax error was in using apostophes to surround your field names. MySQL interprets anything surrounded by ' ' as a value and anything surrounded by ` ` (backticks, your tilde key) as a field. alternatively, you can simply not surround field names with anything at all.
    when I first started using MySQL I had that error and it was making me pull my hair out hehe =) hope you get it working!
    Vada con Fortuna.
    http://www.page1ink.net

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •