Results 1 to 8 of 8

Thread: Need MySQL help

  1. #1
    Join Date
    Aug 2003
    Location
    Western Australia
    Posts
    5

    Need MySQL help

    Hi everyone,

    I need some help with a MySQL/php form, it's complaining about something I've just added and I can't work out what's wrong. Here's the error I got:

    You have an error in your SQL syntax near 'bureauinf='0', churchinf='0', financeinf='0', healthinf='0', highinf='0', indust' at line 1** 1064

    And here's the code for what I added:

    Code:
    $bureauinf=$data['bureauinf'];$churchinf=$data['churchinf'];
    $financeinf=$data['financeinf'];$healthinf=$data['healthinf'];
    $highinf=$data['highinf'];$industryinf=$data['industryinf'];
    $legalinf=$data['legalinf'];$mediainf=$data['mediainf'];
    $occultinf=$data['occultinf'];$policeinf=$data['policeinf'];
    $politicsinf=$data['politicsinf'];$streetinf=$data['streetinf'];
    $transportinf=$data['transportinf'];$underworldinf=$data['underworldinf'];
    $universityinf=$data['universityinf'];
    $sql=$sql."bureauinf='$bureauinf', churchinf='$churchinf', financeinf='$financeinf', healthinf='$healthinf', ";
    $sql=$sql."highinf='$highinf', industryinf='$industryinf', legalinf='$legalinf', mediainf='$mediainf', ";
    $sql=$sql."occultinf='$occultinf', policeinf='$policeinf', politicsinf='$politicsinf', streetinf='$streetinf', ";
    $sql=$sql."transportinf='$transportinf', underworldinf='$underworldinf', universityinf='$unversityinf', ";
    $result=mysql_query($sql);
    Can anyone see what I did wrong?

    Tatha

  2. #2
    Join Date
    Sep 2003
    Posts
    64
    You're ending the SQL query with a comma AND not terminating it with a semicolon, for starters..?

  3. #3
    Join Date
    Aug 2003
    Location
    Western Australia
    Posts
    5
    I saw that and fixed it, but it's still giving me grief

  4. #4
    Join Date
    Sep 2003
    Posts
    64
    What is $sql set to before these lines?

  5. #5
    Join Date
    Sep 2002
    Location
    Illinois
    Posts
    2,307
    PHP Code:
    $sql "SELECT * FROM table WHERE ";

    $bureauinf=$data['bureauinf'];
    $churchinf=$data['churchinf'];
    $financeinf=$data['financeinf'];
    $healthinf=$data['healthinf'];
    $highinf=$data['highinf'];
    $industryinf=$data['industryinf'];
    $legalinf=$data['legalinf'];
    $mediainf=$data['mediainf'];
    $occultinf=$data['occultinf'];
    $policeinf=$data['policeinf'];
    $politicsinf=$data['politicsinf'];
    $streetinf=$data['streetinf'];
    $transportinf=$data['transportinf'];
    $underworldinf=$data['underworldinf'];
    $universityinf=$data['universityinf'];

    $sql .= "bureauinf = '\$bureauinf', churchinf = '\$churchinf', financeinf = '\$financeinf', healthinf = '\$healthinf', ";
    $sql .= "highinf = '\$highinf', industryinf = '\$industryinf', legalinf ='\$legalinf', mediainf = '\$mediainf', ";
    $sql .= "occultinf = '\$occultinf', policeinf = '\$policeinf', politicsinf = '\$politicsinf', streetinf = '\$streetinf', ";
    $sql .= "transportinf = '\$transportinf', underworldinf = '\$underworldinf', universityinf = '\$unversityinf'";

    $result=mysql_query($sql); 
    How's my programming? Call 1-800-DEV-NULL

  6. #6
    Join Date
    Aug 2003
    Location
    Western Australia
    Posts
    5
    Code:
    $sql="Select * from charsheets where name='$charname'";

  7. #7
    Join Date
    Sep 2003
    Posts
    64
    First, scratch those slashes you've added in there before each $.

    Second, there is no space between
    Code:
    $sql = "Select * from charsheets WHERE name='$charname'";
    And the next
    Code:
    $sql .= "bureainf blah blah";
    There needs to be a space.. but more important, there needs to be an AND or an OR, not a comma..

    Example:
    Code:
    $sql = "SELECT * FROM charsheets WHERE name='$charname'";
    $sql .= " AND bureauinf='$bureauinf' AND churchinf='$churchinf' AND financeinf='$financeinf'";
    Can substitute OR for AND. See http://www.mysql.com/doc/en/Selecting_rows.html for more information.

  8. #8
    Join Date
    Jul 2003
    Location
    Kuwait
    Posts
    5,104
    You don't need a semicolon at the end of your query, iirc, it will not execute with a semicolon at the end. You however do need a semicolon to terminate the statement.

    PHP Code:
    // Not this
    $query "SELECT * FROM table WHERE field = 'value';";

    //But this
    $query "SELECT * FROM table WHERE field = 'value'"

Posting Permissions

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