PHP-重定向到另一个页面 [英] PHP- Redirect to another page
问题描述
我的问题很简单.但我太挣扎了.问题是一旦我点击提交按钮,页面应该重定向到其他页面.请告诉我我做错了什么?因为我什么都试过了.
My question is very simple. but I am struggling with it too much. The problem is once I hit the submit button that page should redirect to some other page. Kindly just tell me what I have done wrong? Because I have tried everything.
代码:
更新-docket.php
Update-docket.php
<?php
//error_reporting(0);
$link = mysqli_connect("localhost", "home_db", "root", "");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
// Escape user inputs for security
$sql = 'SELECT * FROM prod_details';
$result = mysqli_query($link,$sql);
while ($row = mysqli_fetch_array($result))
{
$Quantity1 = $_POST['p_'.$row['id']. ''];
$id = $row['id'];
$store = $row['rstore'];
// echo $store;
foreach ($_POST as $key => $value)
{}
if(!empty($Quantity1)) {
$query="update prod_details SET rdocket='$Quantity1' WHERE id='$id'";
if(mysqli_query($link, $query)) {
header('Location: /docket-details.php');
exit();
} else {
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
}
}
docket-details.php
docket-details.php
<form class="form-horizontal" action="update-docket.php" method="post" name="myform" autocomplete="off">
<button type='submit' name='submit' class='btn c-theme-btn c-btn-square c-btn-uppercase c-btn-bold'>Submit</button>
请帮忙!!!
推荐答案
You're Location
行不正确,重定向使用:
You're Location
line is incorrect, redirect using:
header('Location: /url');
https://secure.php.net/manual/en/function.header.php
我认为您的 if 语句没有得到满足.尝试再次启用错误日志记录并在每个条件部分中启用 var_dumping 以查看真正的问题所在.现在您已经更新了代码以使用 header
理论上它应该可以工作.但我的猜测是 $_POST 不会返回您想要/期望的内容.
I reckon your if statement is not being met. Try enabling error logging again and var_dumping inside each conditional section to see where the real problem lies. Now you've updated your code to use header
it should in theory work. But my guess is $_POST not returning what you want/expect.
这篇关于PHP-重定向到另一个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!