//连接库$link = new mysqli('localhost', 'root', 'root', 'login');if (!$link) { die("连接失败: " . mysqli_connect_error());}
$result = $link -> query("SELECT user FROM log WHERE user = "."'$user'");$rs = $result -> fetch_row();if (!empty($rs)) { echo "<script>alert('用户已存在!');location.href='../login.html';</script>";} else { $link = new mysqli('localhost', 'root', 'root', 'login'); $sql="insert into log(user,pwd,sex,age) values('$user','$pwd','$sex','$age')"; $rs = mysqli_query($link,$sql); if (!$rs) { echo "<script>alert('注册失败!');location.href='../login.html';</script>"; } else { echo "<script>alert('注册成功!返回登录页面');location.href='../index.html';</script>"; }}
为什么会注册失败?
数据库也没有写进去数据
打印出sql语句,在mysql工具里面试