0

嘿,我是新来的,任何人都可以帮助我处理 php 和 mysql 中的这段代码,我知道这是一个小错误,但我不知道错误在哪里,谢谢。这是代码:

//index.php

<html>
<head>
<title>Search for a user</title>
</head>
<body>
<h2> Search for a user below:</h2><br /><br />
<form action="profileprocess.php" method="get">
  <table>
   <tr>
    <td>Username:</td><td><input type="text" id="username" name="username" /></td></tr>
    <tr>
    <td><input type="submit" name="submit" id="submit"  value="View Profile" /></td>
    </tr>


  </table>


</form>
</body>
</html>

// profileprocess.php

<html>
<head>
<title><?php echo $username; ?> <?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 t the server");
    mysql_select_db("users") or die("this database was not found");
    $userquery = mysql_query("SELECT * FROM users WHERE username='$username'") or die("the query could be fale please try again");
    if(mysql_num_rows($userquery) != 1){
        die("that username could not be found!");
    }
    while($row = mysql_fetch_array($userquery, MYSQL_ASSOC)){
       $firstname = $row['firstname'];
       $lastname = $row['lastname'];
       $email = $row['email'];
       $dbusername = $row['username'];
       $activated = $row['activated'];
       $access = $row['access'];
       }
       if($username != $dbusername){
         die ("there has been a fatal error please try again. ");
       }
       if($activated == 0){
        $active = "this account has not been activated";
       }else{
          $active = "ths  account has been activated";
       }

       if($access == 0){
         $admin = "this user is not administrator";
       }else{
         $admin = "this user is  an administrator";
       }
?>
<h2><?php echo $username; ?> <?php echo $lastname; ?>s profile</h2>
<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>username:</td><td><?php echo $dbusername; ?></td>
</tr>
<tr>
<td>activated:</td><td><?php echo $active; ?></td>
</tr>
<tr>
<td>access:</td><td><?php echo $admin; ?></td>
</tr>

</table>


<?php      
 }else die("You need  to specify a username!");


?>

</body>
</html>

//// 有什么帮助吗???

4

2 回答 2

2

我只是在我的 XAMPP 服务器上运行此代码,它似乎工作正常。

<html>
<head>
<title>Search for a user</title>
</head>
<body>
<h2> Search for a user below:</h2><br /><br />
<form action="" method="get">
  <table>
   <tr>
    <td>Username:</td><td><input type="text" id="username" name="username" /></td></tr>
    <tr>
    <td><input type="submit" name="submit" id="submit"  value="View Profile" /></td>
    </tr>


  </table>


</form>
</body>
</html>

<?php
 if($_GET['username'] != ''){
     echo $_GET['username'];

 } else 
 die('doesnt work'); ?>
于 2013-02-08T10:19:40.863 回答
0

我肯定看到的一个问题是您在页面开头使用了 echo 并且查询没有运行。这会引发错误。

另外,请告诉我们错误是什么,以便我们可以尝试更好地帮助您。

于 2013-02-08T09:51:56.453 回答