为什么我的查询失败?列在那里。是否存在语法问题或者我应该在其他地方查找?
if (isset($_POST['username']) && isset($_POST['password'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$result = mysqli_query
(
$conn, "INSERT INTO users (username, password) VALUES ('$username','$password')"
);
if($result === false) {
echo 'query failed for some reason';
}
if ($end = mysqli_fetch_array($result) > 0) {
echo "succ";
mysql_close($conn);
} else {
echo 'fail';
die('Could not insert into database:' . mysql_error());
};
}
答案 0 :(得分:0)
如果从mysql_query插入,则在代码中 然后它不会返回行,所以你不需要mysql_fetch_assoc()
if (isset($_POST['username']) && isset($_POST['password'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$result = mysqli_query
(
$conn, "INSERT INTO users (username, password) VALUES ('$username','$password')"
);
if($result === false) {
echo 'query failed for some reason';
die('Could not insert into database:' . mysqli_error($conn));
} else {
echo "succ";
mysqli_close($conn);
}
}