Can't find the error!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Can't find the error!

Post by andym01480 »

Code: Select all

$query1="INSERT INTO 'calevent' (title,description,location,postcode) VALUES('$clean['title']','$clean['description']','$clean['location']','$clean['postcode']')";
is producing this error

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\Program Files\xampp\htdocs\secure\calendar\add.php on line 100

It must be so obvious, but I can't see it!

What's wrong?
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Try this:

Code: Select all

$query1="INSERT INTO 'calevent' (title,description,location,postcode) VALUES('" . $clean['title'] . "','" . $clean['description'] . "','" . $clean['location'] . "','" . $clean['postcode'] . "')";
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Or this...

Code: Select all

<?php
$sql ="INSERT 
        INTO `calevent` (`title`, `description`, `location`, `postcode`) 
        VALUES ('{$clean['title']}', '{$clean['description']}', '{$clean['location']}', '{$clean['postcode']}')";
?>
Notice that I changed the single quotes around the table name to backticks. That could have been causing a problem also. And remember to run some error checking on the query itself, using mysql_error() for failures on mysql_query().
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Post by andym01480 »

Thanks guys. I'd never seen the backstick way before!
I always use error checking on the query in development, but had never had a script fail on the query string itself!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Post Reply