解析错误:语法错误,意外' $ ind'第13行的C:\ xampp server \ htdocs \ Sahith \ sy.php中的(T_VARIABLE)。
运行
时会显示此错误 <?php
$dbhost = 'localhost:3306';
$dbuser = 'root';
$dbpass = '';
$se = ['index'];
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn ) {
die('Could not connect: ' . mysql_error());
}
$sql = 'SELECT * FROM `student` WHERE `Index No.` = '$se'';
mysql_select_db('school');
$retval = mysql_query( $sql, $conn );
if(! $retval ) {
die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_assoc($retval)) {
echo "Index :{$row['Index No.']} <br> ".
"NAME : {$row['Name']} <br> ". "--------------------------------<br>"; }
echo "Fetched data successfully\n";
mysql_close($conn); ?>
此代码
如何解决这个问题?
答案 0 :(得分:0)
这里有语法错误:
$sql = 'SELECT * FROM `student` WHERE `Index No.` = '$se'';
更改为
$sql = 'SELECT * FROM `student` WHERE `Index No.` = "'.$se.'"';
请查看:PHP Parse/Syntax Errors; and How to solve them?
和
警告:您的代码容易受SQL injections攻击,并可能危及数据库和服务器的安全。您应该使用PDO或mysqli API来保护您的SQL查询,并使用prepare
函数。