View Full Version : Syntax Check

08-02-2007, 01:29 PM

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.

$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.

08-02-2007, 01:31 PM
Is the available a text or varchar field?
If so you will need to use " ' " around the inserted element:

query1 = "INSERT INTO vol_available (vol_id, available)
VALUES($vid, '$avalue')";


08-02-2007, 03:06 PM

The single quotes solved the problem.

Thank you for the help.