Page 1 of 1

A mysql error!

Posted: Sun Nov 09, 2008 2:32 pm
by cap2cap10
Greetings php technorati!
:banghead: I keep getting this error in syntax:
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 'references) VALUES ('32', '1281294856', 'I am looking for a position where ' at line 8


Here is the code:

Code: Select all

<?php
if (isset($_POST['submitted']))
{
 
    $userID = $_POST['userID'];
    $candidateID = $_POST['candidateID'];
    $object = $_POST['object'];
    $skills = $_POST['skills'];
    $boss_1 = $_POST['boss_1'];
    $job_title_1 = $_POST['job_title_1'];
    $start_mo_1 = $_POST['start_mo_1'];
    $start_yr_1 = $_POST['start_yr_1'];
    $end_mo_1 = $_POST['end_mo_1'];
    $end_yr_1 = $_POST['end_yr_1'];
    $job_duty_1 = $_POST['job_duty_1'];
    $boss_2 = $_POST['boss_2'];
    $job_title_2 = $_POST['job_title_2'];
    $start_mo_2 = $_POST['start_mo_2'];
    $start_yr_2 = $_POST['start_yr_2'];
    $end_mo_2 = $_POST['end_mo_2'];
    $end_yr_2 = $_POST['end_yr_2'];
    $job_duty_2 = $_POST['job_duty_2'];
    $boss_3 = $_POST['boss_3'];
    $job_title_3 = $_POST['job_title_3'];
    $start_mo_3 = $_POST['start_mo_3'];
    $start_yr_3 = $_POST['start_yr_3'];
    $end_mo_3 = $_POST['end_mo_3'];
    $end_yr_3 = $_POST['end_yr_3'];
    $job_duty_3 = $_POST['job_duty_3'];
    $boss_4 = $_POST['boss_4'];
    $job_title_4 = $_POST['job_title_4'];
    $start_mo_4 = $_POST['start_mo_4'];
    $start_yr_4 = $_POST['start_yr_4'];
    $end_mo_4 = $_POST['end_mo_4'];
    $end_yr_4 = $_POST['end_yr_4'];
    $job_duty_4 = $_POST['job_duty_4'];
    $boss_5 = $_POST['boss_5'];
    $job_title_5 = $_POST['job_title_5'];
    $start_mo_5 = $_POST['start_mo_5'];
    $start_yr_5 = $_POST['start_yr_5'];
    $end_mo_5 = $_POST['end_mo_5'];
    $end_yr_5 = $_POST['end_yr_5'];
    $job_duty_5 = $_POST['job_duty_5'];
    $school_1 = $_POST['school_1'];
    $major_1= $_POST['major_1'];
    $degree_1 = $_POST['degree_1'];
    $year_1 = $_POST['year_1'];
    $school_2 = $_POST['school_2'];
    $major_2 = $_POST['major_2'];
    $degree_2 = $_POST['degree_2'];
    $year_2 = $_POST['year_2'];
    $school_3 = $_POST['school_3'];
    $major_3 = $_POST['major_3'];
    $degree_3 = $_POST['degree_3'];
    $year_3 = $_POST['year_3'];
    $school_4 = $_POST['school_4'];
    $major_4 = $_POST['major_4'];
    $degree_4 = $_POST['degree_4'];
    $year_4 = $_POST['year_4'];
    $school_5 = $_POST['school_5'];
    $major_5 = $_POST['major_5'];
    $degree_5 = $_POST['degree_5'];
    $year_5 = $_POST['year_5'];
    $certificate = $_POST['certificate'];
    $association = $_POST['association'];
    $references = $_POST['references'];
}
    
// Connect to server and select databse.
mysql_connect('************.net', '********', '****************') or die(mysql_error());
mysql_select_db('js_info') or die(mysql_error());
    
    mysql_query("INSERT INTO js_resume (userID, candidateID, object, skills, boss_1, job_title_1,
    start_mo_1, start_yr_1, end_mo_1, end_yr_1, job_duty_1, boss_2, job_title_2, start_mo_2,
    start_yr_2, end_mo_2, end_yr_2, job_duty_2, boss_3, job_title_3, start_mo_3, start_yr_3,
    end_mo_3, end_yr_3, job_duty_3, boss_4, job_title_4, start_mo_4, start_yr_4, end_mo_4,
    end_yr_4, job_duty_4, boss_5, job_title_5, start_mo_5, start_yr_5, end_mo_5, end_yr_5,
    job_duty_5, school_1, major_1, degree_1, year_1, school_2, major_2, degree_2, year_2,
    school_3, major_3, degree_3, year_3, school_4, major_4, degree_4, year_4, school_5,
    major_5, degree_5, year_5, certificate, association, references) VALUES ('$userID', '$candidateID',
    '$object', '$skills', '$boss_1', '$job_title_1', '$start_mo_1', '$start_yr_1', '$end_mo_1', '$end_yr_1',
    '$job_duty_1', '$boss_2', '$job_title_2', '$start_mo_2', '$start_yr_2', '$end_mo_2', '$end_yr_2', '$job_duty_2',
    '$boss_3','$job_title_3','$start_mo_3','$start_yr_3','$end_mo_3', '$end_yr_3','$job_duty_3','$boss_4',
    '$job_title_4', '$start_mo_4', '$start_yr_4', '$end_mo_4', '$end_yr_4', '$job_duty_4', '$boss_5', '$job_title_5',
    '$start_mo_5','$start_yr_5','$end_mo_5','$end_yr_5','$job_duty_5','$school_1','$major_1','$degree_1','$year_1',
    '$school_2', '$major_2', '$degree_2', '$year_2', '$school_3', '$major_3', '$degree_3', '$year_3', '$school_4', '$major_4',
    '$degree_4','$year_4','$school_5','$major_5','$degree_5','$year_5',
     '$certificate', '$association', '$references')") or die(mysql_error());
 
mysql_close();
 
header("Location: upload.php");
?>
[/color]

Can someone please enlighten me?!!!

Thanks in advance,

Batoe

Re: A mysql error!

Posted: Sun Nov 09, 2008 3:04 pm
by oddsmojo
I find it healthy to set the mysql statement as $query. Then send that to the database. In case of an error, echo $query, then run it through phmyadmin to see exactly what it is pushing through. Makes it much easier to find errors.

Re: A mysql error!

Posted: Sun Nov 09, 2008 4:08 pm
by requinix
"references" is a MySQL keyword. It doesn't like it when you try to use keywords in ways that don't make sense.
Add backticks around the field name, like

Code: Select all

mysql_query("INSERT INTO... association, `references`) VALUES ...")