query("set names utf8");
$sql = "SELECT * FROM User WHERE name = $username";
$result = $mysql->query($sql);
//查询返回的记录数
if ($result->num_rows){
while ($result2-$result2->fetch_assoc()) {
if ($result2["password"] == $password) {
echo "登陆成功";
break;
}else {
echo "密码不正确";
break;
}
}
}else{
echo "没有该用户";
}
}elseif(in_array($_REQUEST["username"],$_REQUEST)) {
$username = $_REQUEST["username"];
$password = $_REQUEST["password"];
$mysql = new mysqli("localhost","root","","message");
$mysql->query("set names utf8");
$sql = "INSERT INTO User (name,password) VALUES ('$username','$password')";
$result = $mysql->query($sql);
if ($result) {
echo "插入成功";
}else {
echo "插入失败";
}
}
?>