21,891
社区成员
发帖
与我相关
我的任务
分享
检测用户名是否存在.php
<?php
session_start();
$_SESSION['firstname']=$_GET['hiddenField1'];
$_SESSION['lastname']=$_GET['hiddenField2'];
$_SESSION['email']=$_GET['hiddenField3'];
$_SESSION['psswrd']=$_GET['psswrd'];
$_SESSION['USERID']=$_GET['userid'];
$db = @new mysqli("localhost","root","SERVER","database");
if (mysqli_connect_errno()) {
echo "数据库链接失败!<br>\n";
echo mysqli_connect_error();
exit;
}
$username=$_SESSION['USERID'];
$sql="SELECT * FROM userinfo WHERE Userid= '$username' ";
$rs = $db->query($sql);
if ($rs && $rs->num_rows > 0) {
echo "<script language=javascript>alert('该用户名已存在!');history.back();</script>";}
else {
header("refresh:0;url=http://localhost/Website/userinfo3.php");
exit;
}
$db->close();
?>