Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Syntax Check

  1. #1
    New Coder
    Join Date
    May 2007
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Syntax Check

    Hi,

    I'm running three queries. When the second query is run, I'm receiving the following message:
    Query error:
    INSERT INTO vol_available (vol_id, available) VALUES(14, Weekday mornings)
    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 'mornings)' at line 2

    The data for "available" and "interests" is coming from a form which is using checkboxes.

    Can someone help me out?

    These are my queries.
    Code:
    $query = "INSERT INTO app_vol (vol_name, vol_address, vol_city, vol_state, vol_zip, vol_home_phone,
                vol_work_phone, vol_email, availability, interests, special_skills, prev_exp, vol_em_name,
                vol_em_address, vol_em_city, vol_em_state, vol_em_zip, vol_em_home_phone, vol_em_work_phone,
                vol_em_email, date)
               VALUES ('$_SESSION[realname]','$_SESSION[vol_address]','$_SESSION[vol_city]', '$_SESSION[vol_state]',
                 '$_SESSION[vol_zip]', '$_SESSION[vol_home_phone]', '$_SESSION[vol_work_phone]', '$_SESSION[email]',
                 '$_SESSION[available1]', '$_SESSION[interests1]', '$_SESSION[special_skills]', '$_SESSION[prev_exp]',
                 '$_SESSION[vol_em_name]', '$_SESSION[vol_em_address]','$_SESSION[vol_em_city]', '$_SESSION[vol_em_state]',
                 '$_SESSION[vol_em_zip]', '$_SESSION[vol_em_home_phone]', '$_SESSION[vol_em_work_phone]', '$_SESSION[vol_em_email]', CURRENT_DATE())";		
          $result = mysql_query ($query) or die (mysql_error());
          $vid = @mysql_insert_id();
    
    foreach($_SESSION['available'] as $avalue){
    $query1 = "INSERT INTO vol_available (vol_id, available)
               VALUES($vid, $avalue)";
    $result1 = mysql_query ($query1) or die ("Query error:<br>$query1<br>".mysql_error());
    }
    
    foreach($_SESSION['interests'] as $ivalue){
    $query2 = "INSERT INTO vol_interests (vol_id, interests)
               VALUES($vid, $ivalue)";
    
    $result2 = mysql_query ($query2) or die (mysql_error());
    }
    I can't seem to figure out what is causing this.

  • #2
    Regular Coder
    Join Date
    Jun 2007
    Location
    N. Ireland
    Posts
    351
    Thanks
    16
    Thanked 4 Times in 4 Posts
    Is the available a text or varchar field?
    If so you will need to use " ' " around the inserted element:
    PHP Code:
    query1 "INSERT INTO vol_available (vol_id, available)
               VALUES($vid, '$avalue')"

    D.
    Daemonkin.
    If this was helpful, please add to my reputation
    Thousand Sons - Freelance Web Developer - ninetyonedegrees.com

  • #3
    New Coder
    Join Date
    May 2007
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    The single quotes solved the problem.

    Thank you for the help.


  •  

    Posting Permissions

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