gpt4 book ai didi

php - SQL插入查询返回false

转载 作者:行者123 更新时间:2023-11-28 23:59:45 24 4
gpt4 key购买 nike

为什么我的查询失败了?专栏在那里。有语法问题还是我应该去别处看看?

 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());
};
}

最佳答案

如果您从 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);
}
}

关于php - SQL插入查询返回false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30305083/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com