Hey, yeah, I've tried so many times to get rid of this error:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
I'm thinking it's a sql problem, but it's only a simple query I'm runni开发者_运维知识库ng. Any help would be greatly appreciated.
$connDB = mysql_connect($host, $user, $pass)
or die("Connect Error: ".mysql_error());
$sql = "SELECT * FROM `images` WHERE `iimageid` = '" . $iimageid . "'";
$runSQL = mysql_query($sql, $connDB);
echo $sql;
?>
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td valign="top">
<? while($display_info = mysql_fetch_array($runSQL)) { ?>
<a href="sfd/pimages/<? echo $display_info['vimage']; ?>" rel="lightbox[g]"><img src="sfd/pimages/thumb/"<? echo $display_info['vimage']; ?>">
<br>
<? } ?>
</td>
</tr>
</table>
</td>
Ok nm, I found it pretty quickly after submitting this thing. $iimageid wasn't being pulled, taken care of now. :)
Try this (Without the ticks)
$sql = "SELECT * FROM images WHERE iimageid = '" . $iimageid . "'";
or (typecasting to integer)
$sql = "SELECT * FROM images WHERE iimageid = ". (int)$iimageid;
If its an integer value always typecast to integer, then any text string it will automatically set to 0 "For security purposes"
It looks like your SQL statement is invalid to me, try:
"SELECT * FROM images WHERE iimageid = '" . $iimageid . "'";
Looks like a PHP error to me, not MySQL. Those error codes are normally by the PHP interpreter finding something it doesn't like in your code. You also appear to have not closed off the <a> tag? And there appears to be an extra " after your 'thumb/' part of the <img> tag.
I would re-write this section;
<? while($display_info = mysql_fetch_array($runSQL)) { ?>
<a href="sfd/pimages/<? echo $display_info['vimage']; ?>" rel="lightbox[g]"><img src="sfd/pimages/thumb/"<? echo $display_info['vimage']; ?>">
<br>
<? } ?>
As follows, see if that helps.
<?
while ( $display_info = mysql_fetch_array($runSQL) ) {
print "<a href=\"sfd/pimages/{$display_info['vimage']}\" rel=\"lightbox[g]\">";
print "<img src=\"sfd/pimages/thumb/{$display_info['vimage']}\">";
print "</a><br>\n";
}
?>
Everytime someone uses mysql_* functions, baby raptor jesus eats a lolcat. You should start using PDO ( http://fr.php.net/manual/en/book.pdo.php ), and for the part mixing html and php you may prefer the alternative syntax http://www.php.net/manual/en/control-structures.alternative-syntax.php
精彩评论