t encapsed whitespace problem

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
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

t encapsed whitespace problem

Post by a94060 »

i think i have asked enough simple/dumb questinos,but here is another one. I have this code:

Code: Select all

if($_SESSION['in'] != 'yes' ) {
echo '<font color=red>You are not logged in,please go <a href="../admin">Here</a> to login.</font>';
}
else {
/*the action page.all actions of the admin will be redirected here.
That is all*/
$act = $_GET['act'];
$entry = $_GET['entry'];//the id of the entry
	if($act == 'approve') {
	$query = "SELECT * FROM poffers WHERE id=$entry";
	$result = mysql_query($query);
	$data = mysql_fetch_array($result,MYSQL_ASSOC);
	$sql2 = "INSERT INTO coffers(username,offer_name,offer_type) VALUES ($data['username'],$data['offer_name'], 					$data['offer_type'])";
	$sql2run = mysql_query($sql2);//inserts the offer to completed table.
	//remove it from the old table
	$put = mysql_num_rows($sql2run);
		if($put == 1) {
		$delete = "DELETE FROM poffers WHERE id=$entry LIMIT 1";
		$delrun = mysql_query($delete);
		$hits = mysql_num_rows($delrun);
			if($hits == '1') {
			echo 'The offer' .$entry.'has been removed from pending offers and has been moved to completed offers.';
			}
			else{
			echo 'The entry was not added.';
			}
		}
	}
}
It tells me :
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\xampplite\htdocs\admin\do.php on line 26
im pretty sure there is no white space on that line. by the array. i think it might be problem with array though.
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Post by bdlang »

Ok, so which line is 26? The one that starts "echo 'The offer..." Is that the entire script?

Your INSERT statement could use some rework:

Code: Select all

$sql2 = "INSERT INTO coffers(username,offer_name,offer_type) VALUES ($data['username'],$data['offer_name'],                     $data['offer_type'])";
There is no space between coffers and the opening parenthesis, you haven't surrounded the SQL data in quotes, and you have a weird gap in between the values.

Try

Code: Select all

$sql2 = "INSERT INTO coffers (username,offer_name,offer_type) VALUES ('{$data['username']}', '{$data['offer_name']}', '{$data['offer_type'])}'";
Post Reply