21,886
社区成员
发帖
与我相关
我的任务
分享
<?php
header('Content-Type:textml;charset=utf-8');
$username='游客';
//获取用户输入的账号和密码并连接数据库
$account=$_POST['account'];
$password=$_POST['password'];
$db=new mysqli('localhost','root','12345678','newsmanage');
//查询数据库是否已经有相同账号
$query1=$db->prepare("SELECT account FROM user");
$query1->bind_result($theaccount);
$query1->execute();
while($query1->fetch()) {
if ($account == $theaccount) {
echo '<script>alert("该账号已被注册!");location.href="register.html"</script>';
exit();
}
}
//将用户输入的账号和密码写入数据库
$add=$db->prepare("INSERT INTO user VALUES (null,'general',null,?,?)");
$add->bind_param('ss',$account, $password);
$add->execute();
//数据库对添加的新用户自动生成唯一ID,查寻此ID并赋值变量
$query2=$db->prepare("SELECT userid FROM user WHERE account='$account'");
$query2->bind_result($userid);
$query2->execute();
$query2->fetch();
//用username变量修改数据表中的数据
$edit=$db->prepare("UPDATE user SET username=? WHERE account=?");
$edit->bind_param('ss',$username,$account);
$edit->execute();
//报错提示:Call to a member function bind_param() on boolean in
echo '<script>alert("恭喜您,注册成功!");location.href="../login/login.html"</script>';
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="register.css">
<script src="../jQuery-3.3.1.js"></script>
<title>用户注册</title>
</head>
<body>
<img id="background" class="blur2" src="image/background.png" alt="background">
<div id="top">
<img id="logo" src="image/logo.jpg" alt="logo">
<div id="back">返回</div>
<div id="register">用户注册</div>
</div>
<form id="card" action="register.php" method="post">
<img id="headportrait" src="image/headportrait.jpg" alt="headportrait">
<div id="addheadportrait">添加头像</div>
<label for="account" id="accountname">账号</label>
<input type="text" id="account" name="account" placeholder="请输入账号">
<br>
<label for="password" id="passwordname">密码</label>
<input type="password" id="password" name="password" placeholder="请输入密码">
<br>
<input type="button" id="delete" value="重新填写">
<input type="submit" id="send" value="提交注册">
</form>
<script src="register.js"></script>
</body>
</html>
<?php
//数据库对添加的新用户自动生成唯一ID,查寻此ID并赋值变量
$query2=$db->prepare("SELECT userid FROM user WHERE account='$account'");
$query2->bind_result($userid);
$query2->execute();
$query2->fetch();