2014-10-19 74 views
-1

我是一个编程和PHP的完全新手,我的代码抛出一个错误,说有一个意外的结束的文件,我不能为我的生活看到什么是缺少的或那里不应该是。任何人都可以发现它?PHP解析错误 - 意外的文件结尾

<html> 
 
<head> 
 
<title><?php echo $firstname; ?> <?php echo $lastname; ?>'s Profile</title> 
 
</head> 
 
<body> 
 
<?php 
 

 
if (isset($_GET['username'])){ 
 
    \t $username = $_GET['username']; 
 
    mysql_connect("localhost","root", "") or die ("Could not connect to the server"); 
 
    mysql_select_db("users") or die ("That database could not be found."); 
 
\t $userquery = mysql_query("SELECT * FROM users WHERE username='$username'") or die ("The query could not be completed, please try again later."); 
 
\t if(mysql_num_rows($userquery) !=1){ 
 
\t \t die ("That user could not be found."); 
 
\t } 
 
\t while($row = mysql_fetch_array($userquery, MYSQL_ASSOC)) { 
 
\t \t $firstname = $row['firstname']; 
 
\t \t $lastname = $row['lastname']; 
 
\t \t $email = $row['email']; 
 
\t \t $dbusername = $row['dbusername']; 
 
\t \t $access = $row['access']; 
 
\t \t } 
 
\t \t if($username != $dbusername){ 
 
\t \t \t die ("There has been a fatal error, please try again."); \t \t 
 
\t \t } 
 
\t 
 
\t \t if($access == 1) { 
 
\t \t \t $access = "Level 1 User"; 
 
\t \t } else 
 
\t \t \t if($access == 2) { 
 
\t \t \t \t $access = "Level 2 User"; 
 
\t \t \t } \t else 
 
\t \t \t \t \t if($access == 3) { 
 
\t \t \t \t \t \t $access = "Level 3 User"; 
 
\t \t \t \t \t } else 
 
\t \t \t \t \t \t if($access == 4) { 
 
\t \t \t \t \t \t \t $access = "Administrator."; 
 
\t \t \t \t \t \t } else die ("This user has an access level beyond the realms of possibility. Beware."); 
 
\t 
 
\t \t \t \t \t 
 

 
?> 
 

 
<h2><?php echo $firstname; ?> <?php echo $lastname; ?>'s Profile</h2><br /> 
 
<table> 
 
\t <tr><td>Firstname:</td><td><?php echo $firstname; ?></td></tr> 
 
    <tr><td>Lastname:</td><td><?php echo $lastname; ?></td></tr> 
 
    <tr><td>email:</td><td><?php echo $email; ?></td></tr> 
 
\t <tr><td>dbusername:</td><td><?php echo $dbusername; ?></td></tr> 
 
\t <tr><td>access:</td><td><?php echo $access; ?></td></tr> 
 
</table> 
 
</body> 
 
</html>

+0

哪里while循环结束? – Jocelyn 2014-10-19 06:00:28

回答

0

是主要的,如果需要的代码块有被关闭}

<html> 
 
<head> 
 
<title><?php echo $firstname; ?> <?php echo $lastname; ?>'s Profile</title> 
 
</head> 
 
<body> 
 
<?php 
 

 
if (isset($_GET['username'])){ 
 
    \t $username = $_GET['username']; 
 
    mysql_connect("localhost","root", "") or die ("Could not connect to the server"); 
 
    mysql_select_db("users") or die ("That database could not be found."); 
 
\t $userquery = mysql_query("SELECT * FROM users WHERE username='$username'") or die ("The query could not be completed, please try again later."); 
 
\t if(mysql_num_rows($userquery) !=1){ 
 
\t \t die ("That user could not be found."); 
 
\t } 
 
\t while($row = mysql_fetch_array($userquery, MYSQL_ASSOC)) { 
 
\t \t $firstname = $row['firstname']; 
 
\t \t $lastname = $row['lastname']; 
 
\t \t $email = $row['email']; 
 
\t \t $dbusername = $row['dbusername']; 
 
\t \t $access = $row['access']; 
 
\t \t } 
 
\t \t if($username != $dbusername){ 
 
\t \t \t die ("There has been a fatal error, please try again."); \t \t 
 
\t \t } 
 
\t 
 
\t \t if($access == 1) { 
 
\t \t \t $access = "Level 1 User"; 
 
\t \t } else 
 
\t \t \t if($access == 2) { 
 
\t \t \t \t $access = "Level 2 User"; 
 
\t \t \t } \t else 
 
\t \t \t \t \t if($access == 3) { 
 
\t \t \t \t \t \t $access = "Level 3 User"; 
 
\t \t \t \t \t } else 
 
\t \t \t \t \t \t if($access == 4) { 
 
\t \t \t \t \t \t \t $access = "Administrator."; 
 
\t \t \t \t \t \t } else die ("This user has an access level beyond the realms of possibility. Beware."); 
 
}//THIS IS WHAT IS MISSING 
 
\t \t \t \t \t 
 

 
?> 
 

 
<h2><?php echo $firstname; ?> <?php echo $lastname; ?>'s Profile</h2><br /> 
 
<table> 
 
\t <tr><td>Firstname:</td><td><?php echo $firstname; ?></td></tr> 
 
    <tr><td>Lastname:</td><td><?php echo $lastname; ?></td></tr> 
 
    <tr><td>email:</td><td><?php echo $email; ?></td></tr> 
 
\t <tr><td>dbusername:</td><td><?php echo $dbusername; ?></td></tr> 
 
\t <tr><td>access:</td><td><?php echo $access; ?></td></tr> 
 
</table> 
 
</body> 
 
</html>

+0

谢谢!我有一种感觉,那就是在那个地方,但我无法发现它。 – TFrost 2014-10-19 06:04:19

+0

请接受答案 – muimota 2014-10-19 07:39:06

相关问题