[英]How to redirect URL by id in PHP while inserting data into database
This is my code of inserting data into database.这是我将数据插入数据库的代码。 so i want redirect to other page by clients_id in URL.so i can access in other page.
所以我想通过 URL 中的 clients_id 重定向到其他页面。这样我就可以在其他页面中访问。
if(isset($_POST['upload_product'])) {
$clients_id = $_POST['clients_id'];
$_SESSION['clients_id'] = $clients_id;
$get_product = "INSERT into tb_product(product_description,product_quantity,hsn_code,remarks,price,tracking_id,dc_no,clients_id) Values('$product_description','$product_quantity','$hsn_code','$remarks','$price','$tracking_id','$dc_no','$clients_id')";
if(mysqli_query($con,$get_product))
{
?>
<script>
swal({
title: "Congratulations!",
text: "Products Added Successfully",
type: "success",
timer: 2000,
showConfirmButton: false
}, function(){
// header("Location: ClientsProductList.php?clients_id=".urlencode($current_id['id']);
window.location.href = 'ClientsProductList.php??clients_id='.$_SESSION['clients_id'];
});
</script>
<?php
} else {
echo "Error in registering...Please try again later!";
echo "Error!".$get_product."<br>". mysqli_error($con);
}
try to change this line:尝试更改此行:
window.location.href = 'ClientsProductList.php??clients_id='.$_SESSION['clients_id'];
to:到:
window.location.href = 'ClientsProductList.php?clients_id='.<?php echo $_SESSION['clients_id']; ?>;
For redirection you can use JavaScript or directly you can use php also Like this.对于重定向,您可以使用 JavaScript 或直接使用 php 也像这样。
header('location:ClientsProductList.php?Id=' . $clients_id);
or in JavaScript或在 JavaScript 中
window.location.assign('ClientsProductList.php?id=' + clientid)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.