MySQL Error

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
fullfocus
Forum Commoner
Posts: 33
Joined: Fri Jun 30, 2006 2:51 pm

MySQL Error

Post by fullfocus »

Hello:

I was wondering whether I could get a second pair of eyes on a query. I can't seem to find the problem.

I'm trying to run this query and I'm receiving the following 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 'condition, exc_comments, good_comments, fair_comments, fair' at line 3

I've used this query in other scripts, using different table names and fields, and the query worked without a problem. I don't know why this particular one isn't working.

I hope someone can help me out. Thank you in advance. Here's the query.

Code: Select all

$query8 = "REPLACE INTO discharge_summary (client_id, now1_date, discharge_name, discharge_address, discharge_city, discharge_state, discharge_zip, discharge_phone,
                   discharge_relation, type_id, discharge_date, services_received, present_mood, rep_name, rep_address,
                   rep_city, rep_state, rep_zip, rep_phone, rep_amount, left_desire, left_undesire, condition, 
                   exc_comments, good_comments, fair_comments, fair_poor_comments, poor_comments, notify, notify_relation,
                   services_summary, summary_goals, summary_problems, summary_needs)
          VALUES ('$_POST[client_id]', '$_POST[now1_date]', '$_POST[discharge_name]', '$_POST[discharge_address]', '$_POST[discharge_city]', '$_POST[discharge_state]',
                 '$_POST[discharge_zip]', '$_POST[discharge_phone]', '$_POST[discharge_relation]', '$_POST[type_id]', '$_POST[discharge_date]', 
                 '$services_received3', '$_POST[present_mood]', '$_POST[rep_name]', '$_POST[rep_address]', '$_POST[rep_city]', 
                 '$_POST[rep_state]', '$_POST[rep_zip]', '$_POST[rep_phone]', '$_POST[rep_amount]', '$_POST[left_desire]', '$_POST[left_undesire]', 
                 '$condition3', '$_POST[exc_comments]', '$_POST[good_comments]', '$_POST[fair_comments]', '$_POST[fair_poor_comments]', '$_POST[poor_comments]', 
                 '$_POST[notify]', '$_POST[notify_relation]', '$_POST[services_summary]', '$_POST[summary_goals]', '$_POST[summary_problems]', 
                 '$_POST[summary_needs]')";
                 		
$result8 = mysql_query ($query8) or die ("Query error:<br>$query8<br>".mysql_error());
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Post by bdlang »

Your error message says it all. condition is a reserved word in MySQL, you cannot use it as a column name. My guess is that you've possibly used phpMyAdmin or had previously used `backticks` to run this query.

Either use `backticks` (workaround) or rename the column (best practice).

You should also strongly consider NOT allowing POST data to just go straight into the database unvalidated and unescaped.
fullfocus
Forum Commoner
Posts: 33
Joined: Fri Jun 30, 2006 2:51 pm

Post by fullfocus »

Yes, I didn't realize I used a reserved word. Thanks for catching it.
Post Reply