我是编程和php的完全新手,我的代码抛出一个错误,说文件有意外的结束,我不能在我的生活中看到缺少的东西或不应该的东西。有谁能发现它?
<html>
<head>
<title><?php echo $firstname; ?> <?php echo $lastname; ?>'s Profile</title>
</head>
<body>
<?php
if (isset($_GET['username'])){
$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.");
$userquery = mysql_query("SELECT * FROM users WHERE username='$username'") or die ("The query could not be completed, please try again later.");
if(mysql_num_rows($userquery) !=1){
die ("That user could not be found.");
}
while($row = mysql_fetch_array($userquery, MYSQL_ASSOC)) {
$firstname = $row['firstname'];
$lastname = $row['lastname'];
$email = $row['email'];
$dbusername = $row['dbusername'];
$access = $row['access'];
}
if($username != $dbusername){
die ("There has been a fatal error, please try again.");
}
if($access == 1) {
$access = "Level 1 User";
} else
if($access == 2) {
$access = "Level 2 User";
} else
if($access == 3) {
$access = "Level 3 User";
} else
if($access == 4) {
$access = "Administrator.";
} else die ("This user has an access level beyond the realms of possibility. Beware.");
?>
<h2><?php echo $firstname; ?> <?php echo $lastname; ?>'s Profile</h2><br />
<table>
<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>
<tr><td>dbusername:</td><td><?php echo $dbusername; ?></td></tr>
<tr><td>access:</td><td><?php echo $access; ?></td></tr>
</table>
</body>
</html>
答案 0 :(得分:0)
主要的if代码块是否需要用}
关闭
<html>
<head>
<title><?php echo $firstname; ?> <?php echo $lastname; ?>'s Profile</title>
</head>
<body>
<?php
if (isset($_GET['username'])){
$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.");
$userquery = mysql_query("SELECT * FROM users WHERE username='$username'") or die ("The query could not be completed, please try again later.");
if(mysql_num_rows($userquery) !=1){
die ("That user could not be found.");
}
while($row = mysql_fetch_array($userquery, MYSQL_ASSOC)) {
$firstname = $row['firstname'];
$lastname = $row['lastname'];
$email = $row['email'];
$dbusername = $row['dbusername'];
$access = $row['access'];
}
if($username != $dbusername){
die ("There has been a fatal error, please try again.");
}
if($access == 1) {
$access = "Level 1 User";
} else
if($access == 2) {
$access = "Level 2 User";
} else
if($access == 3) {
$access = "Level 3 User";
} else
if($access == 4) {
$access = "Administrator.";
} else die ("This user has an access level beyond the realms of possibility. Beware.");
}//THIS IS WHAT IS MISSING
?>
<h2><?php echo $firstname; ?> <?php echo $lastname; ?>'s Profile</h2><br />
<table>
<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>
<tr><td>dbusername:</td><td><?php echo $dbusername; ?></td></tr>
<tr><td>access:</td><td><?php echo $access; ?></td></tr>
</table>
</body>
</html>
&#13;