GreenFanta Posted December 15, 2010 Share Posted December 15, 2010 Hey Guys! I've been looking through my script to see what the problem could be, I've got a variable setup to generate a web page, I have no idea what could be the problem, I keep receiving the error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in home/path/etc on line 8 But I don't see any miss-matching Quotations etc... I don't know what the problem could be, maybe you could help me? Code: 1 <?php 2 $content = "<?php 3 $productid = 1; 4 $sql = 'SELECT * FROM table1 WHERE productid =' . $productid . ''; 5 if ($result = mysql_query($sql)) { 6 if (mysql_num_rows($result)) { 7 $row = mysql_fetch_assoc($result); 8 $leader = $row['leader']; 9 } 10 } 11 ?>"; 12 echo($content); 13 ?> Thanks! Regards Matthew Link to comment https://forums.phpfreaks.com/topic/221786-t_encapsed_and_whitespace/ Share on other sites More sharing options...
kenrbnsn Posted December 15, 2010 Share Posted December 15, 2010 What are you trying to do? Since you enclosed the string in double quotes, PHP is trying to do variable substitution withing the string and you can't put a quoted array reference inside a double quoted string. Either enclose the string in single quotes or quote all the $ so the variable names aren't seen as variable names: <?php $content = '<?php $productid = 1; $sql = "SELECT * FROM table1 WHERE productid =\'" . $productid . "\'"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); $leader = $row["leader"]; } } ?>'; echo($content); ?> or <?php $content = "<?php \$productid = 1; \$sql = 'SELECT * FROM table1 WHERE productid ='\" . $productid . \"'\"; if (\$result = mysql_query(\$sql)) { if (mysql_num_rows(\$result)) { \$row = mysql_fetch_assoc(\$result); \$leader = \$row['leader']; } } ?>"; echo($content); ?> Ken Link to comment https://forums.phpfreaks.com/topic/221786-t_encapsed_and_whitespace/#findComment-1147798 Share on other sites More sharing options...
GreenFanta Posted December 15, 2010 Author Share Posted December 15, 2010 Thank you very much! Link to comment https://forums.phpfreaks.com/topic/221786-t_encapsed_and_whitespace/#findComment-1147812 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.