//連線庫$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工具裡面試