提问人:Amahle Lethabo 提问时间:1/6/2021 最后编辑:DharmanAmahle Lethabo 更新时间:1/6/2021 访问量:38
插入查询后重定向,执行不起作用 [duplicate]
Redirecting after inserting query execution not working [duplicate]
问:
我一直在尝试在插入数据库后重定向,但它不起作用。插入工作正常,但它没有重定向,这是我的代码
if (count($errors) == 0) {
$query = "INSERT INTO investment (userid, amount, status, hashID, plan)
VALUES('$uidb', '$amount', '$status', '$id', '$plan')";
$results = mysqli_query($db, $query);
if (mysqli_num_rows($results) == 1) {
exit(header('location: https://google.com'));
}else {
array_push($errors, "Invalid Sort Code");
}
}
答:
-1赞
Alexander Dobernig
1/6/2021
#1
正如 @AbraCadaver 和 @Lars Stegelitz 评论的那样,试试这个:
但更好的是,通过为投注者安全准备好的声明来做到这一点。
if (count($errors) == 0) {
$query = "INSERT INTO investment (userid, amount, status, hashID, plan)
VALUES('$uidb', '$amount', '$status', '$id', '$plan')";
$results = mysqli_query($db, $query);
if (mysqli_affected_rows($db)) == 1) {
header('location: https://google.com');
}else {
array_push($errors, "Invalid Sort Code");
}
}
评论
0赞
Amahle Lethabo
1/6/2021
非常感谢,这成功了,上帝保佑你
评论
0
exit(header('location: https://google.com'));
-为什么?!?请将其分开header('Location: ...'); exit;