<!DOCTYPE html> <html> <head> <title>登录界面</title> <meta charset="utf-8"> </head> <body> <form method="post"> 用户名:<input type="text" name="user_name" value=""><input type="submit" name="submit" value="查看用户名是否被占用"> </form> </body> </html> <?php if (isset($_POST[‘submit‘])) { $us = $_POST["user_name"]; $conn = mysqli_connect(‘localhost‘,‘root‘) or die("无法连接到服务器"); mysqli_select_db($conn,‘shiyan‘); $sql = "select * from student where name=‘$us‘"; $result = mysqli_query($conn,$sql); $num = mysqli_num_rows($result); mysqli_close($conn); if($num >0) { echo "<script>alert(‘该用户名已被占用‘);</script>"; } else { echo "<script>alert(‘该用户名未被占用‘);</script>"; } } ?>