当我在浏览器中查看我的php代码时出现此错误。 解析错误:语法错误,第17行意外的$ end。
<?php
$host="host";
$username="username";
$password="password";
$db_name="db";
$tbl_name="users";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM `users` WHERE `username` = '$_SESSION[username]' ";
$result=mysql_query($sql);
while($row = mysql_fetch_array($result)){
if ( $row['perm'] == "admin" ) {
echo "Admin<br />";
} else {
echo "Welcome to my homepage!";
}
?>
答案 0 :(得分:0)
您缺少while语句的结束花括号。您还应该使用MySQLi或PDO而不是旧的mysql函数。以下是即将推出的PHP版本中支持的新功能的参考。我发现这是一个非常方便的教程&amp;过去的参考指南。 http://www.pontikis.net/blog/how-to-use-php-improved-mysqli-extension-and-why-you-should
<?php
$host="host";
$username="username";
$password="password";
$db_name="db";
$tbl_name="users";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM `users` WHERE `username` = '$_SESSION[username]' ";
$result=mysql_query($sql);
while($row = mysql_fetch_array($result)){
if ( $row['perm'] == "admin" ) {
echo "Admin<br />";
} else {
echo "Welcome to my homepage!";
}
}
?>