如何正确重定向,重定向时,查询不会将值输入数据库
How to properly redirect, when redirecting, query wont input values into database
如何
正确重定向到另一个页面? 这是我的代码。
<link rel="stylesheet" type="text/css" href="payout.css"/>
<font face='calibri'>
<?php
session_start();
$conn = @mysql_connect("localhost","root","mypassword");
$db = @mysql_select_db("buybranded");
include("includes/functions.php");
mysql_set_charset("UTF8");
if(isset($_GET['command']) && $_GET['command']=='update'){
$first_name=$_SESSION['first_name'];
$email=$_SESSION['email'];
$home_address=$_SESSION['home_address'];
$mobile_phone=$_SESSION['mobile_phone'];
$carrier=$_REQUEST['carrier'];
$payment=$_REQUEST['payment'];
$result=mysql_query("insert into customers values('','$first_name','$email','$home_address','$mobile_phone','$carrier','$payment')");
$customerid=mysql_insert_id();
date_default_timezone_set("Asia/Hong_Kong");
$date=date('Y-m-d h:i:s');
$result=mysql_query("insert into orders values('','$date','$customerid')");
$orderid=mysql_insert_id();
$max=count($_SESSION['cart']);
for($i=0;$i<$max;$i++){
$pid=$_SESSION['cart'][$i]['productid'];
$q=$_SESSION['cart'][$i]['qty'];
$price=get_prod_price($pid);
mysql_query("insert into order_detail values ($orderid,$pid,$q,$price)");
}
}
// else if(isset($_REQUEST['success']) && $_REQUEST['success']=='1'){
// header('refresh: 0; url=samplebrand.php');
// $message = "Thank you for buying, You will now be redirected";
// echo("<script type='text/javascript'>alert('$message');</script>");
// }
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Billing Info</title>
<script language="javascript">
function validate(){
var f=document.form1;
f.command.value='update';
f.submit();
alert("Order submitted");
}
</script>
</head>
<body>
<form name="form1" onsubmit="return validate()">
<input type="hidden" name="command" />
<div align="center">
<h1 align="center">Shipping and Payment</h1>
<table border="0" cellpadding="2px">
<tr><td>Order Total:</td><td>₱ <?php echo get_order_total()?></td><td> </td>
</tr>
</table>
<center><h1>Shipping Method</h1></center>
<form method="post">
<table width="900" border="0" align="center" cellpadding="2" cellspacing="0" id='center'>
<tr>
<td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="LBC") echo "checked";?> value="LBC"></td>
<td><img src="img/LBC.jpg" alt="LBC" class="picture"/></td>
<td><p>The Shipping takes 1-2 days for NCR and 2-3 days for any provincial.<p></td>
</tr>
<tr>
<td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="COD") echo "checked";?> value="COD"></td>
<td><img src="img/Cash on Delivery.jpg" alt="COE" class="picture" height="90" width="125"/></td>
<td><p>This service is only available for Meto Manila and Metro Cebu.<p></td>
</tr>
<tr>
<td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="Personal") echo "checked";?> value="Personal"></td>
<td><img src="img/buybranded2.jpg" alt="buybranded" class="picture"/></td>
<td><p>The Shipping takes 2-3 days after processing for NCR and 3-5 days for any provincial.<p></td>
</tr>
<tr>
<td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="NextDayDelivery") echo "checked";?> value="NextDayDelivery"></td>
<td><img src="img/NextdayDelivery.jpg" alt="NextDayDelivery" class="picture"/></td>
<td><p>The Shipping takes 1-2 days for NCR and 2-3 days for any provincial.<p></td>
</tr>
<tr>
<td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="SameDayDelivery") echo "checked";?> value="SameDayDelivery"></td>
<td><img src="img/Same day Delivery.jpg" alt="SameDayDelivery" class="picture"/></td>
<td><p>Available only for NCR. Get your sporting good/s the same day you purchase the item. Cutoff is 12noon.<p></td>
</tr>
<tr>
<td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="PickUp") echo "checked";?> value="PickUp"></td>
<td><img src="img/Pick-up.jpg" alt="Pick-Up" class="picture"/></td>
<td><p>Office hours: 10:00 am to 6:00 pm<p></td>
</tr>
</table>
<br>
<br>
<center><h1>Payment Method</h1></center>
<table width="900" border="0" align="center" cellpadding="2" cellspacing="0" id='centerdown'>
<tr>
<td><input type="radio" name="payment" <?php if (isset($payment) && $payment=="BPI") echo "checked";?> value="BPI"></td>
<td><img src="img/BPI.jpg"></td>
<td><p>Pay by BPI bank deposit (we need confirmation of payment through email.)<p></td>
</tr>
<!--
<tr>
<td><input type="radio" name="payment" <?php if (isset($payment) && $payment=="PayPal") echo "checked";?> value="PayPal"></td>
<td><img src="img/paypal.gif"></td>
<td><p>Pay with your PayPal account, credit card (CB, Visa, Mastercard...), or private credit card.<p></td>
</tr>
-->
<tr>
<td><input type="radio" name="payment" <?php if (isset($payment) && $payment=="PickUp") echo "checked";?> value="PickUp"></td>
<td><img src="img/cashondelivery.gif"></td>
<td><p>Pick up. You have 5 days reservation period. You pay for the merchandise upon pick-up<p></td>
</tr>
<tr>
<td><input type="radio" name="payment" <?php if (isset($payment) && $payment=="COD") echo "checked";?> value="COD"></td>
<td><img src="img/Cash on Delivery.jpg" height="90" width="125"/></td>
<td><p>Pay with your Cash on Delivery (COD)<br>Choose this option if you have selected COD under shipping. Otherwise, choose other options for payment.<p></td>
</tr>
</table>
<table>
<tr><td><input type="submit" value="Place Order"/></td></tr>
</table>
</form>
</div>
</form>
</body>
</html>
而且我的代码的注释部分也不起作用。 我很难解决这个问题。
当我添加 action="billingredirect.php" 时,它不会将查询输入到数据库中。 但是当我删除它时,它会插入查询。
如果您对我的账单重定向感到好奇.php这里是
<?php
header('refresh: 0;url=lorem.html');
$message = "You will now be redirected";
echo("<script type='text/javascript'>alert('$message');</script>");
?>
当我在脚本中添加重定向代码时,它不起作用
<script language="javascript">
function validate(){
var f=document.form1;
f.command.value='update';
f.submit();
alert("Order submitted");
}
</script>
die('hehe');
尝试在 php 标签中添加该行代码,在最后一个 } 之前以停止脚本。检查它是否有效
要重定向到其他页面/脚本,请使用:
header("location: location.php");
exit(); //stops the current script executing
您似乎正在使用超级全局$_GET
,该检索URL的查询字符串中的数据。通常它出现在 ?在地址栏中。它的作用是从GET请求中获取所有数据。超级全局$_POST
从 POST 请求中检索数据。
表单通常会发送 POST 请求,您不会进入 IF
语句。
为了确保这一点,请尝试使用var_dump($_GET)
或var_dump($_POST)
这将打印出所有内容,这样您就可以验证出了什么问题。
在表单提交时重定向时,表单数据不会跟随到新页面。表单数据的处理应在执行重定向的脚本中完成。
相关文章:
- 根据输入的数据重定向到页面的窗体
- 重定向至“基于输入值的页面”诊断树
- 用户在文本框中输入一个数字,并根据使用 PHP 输入的数字重定向到另一个网页
- 提交的表单重定向到输入URL
- 在 aspx 页上输入触发响应的键.重定向
- 样式<输入类型=“范围”>用于重定向,在触摸设备上不起作用
- 输入密码后的JavaScript简单重定向
- 如何使用 php 重定向到上一页并保持所有填充的输入相同
- 基于表单输入的 Javascript 重定向
- 我正在尝试制作一个nocatsplash页面 - 它使用HTML代码来检查密码并在输入正确的密码时重定向访问者
- 如何在输入错误的用户名和/或密码时将用户从登录控件重定向到错误页面
- 如何在单击输入时重定向到其他网页
- javascript重定向到带有表单操作post的页面,然后返回到带有输入值的上一页
- 基于用户输入的关键字重定向
- 需要按钮帮助从下拉菜单获取输入以进行重定向
- 如何使用MozillaRhino中文件的重定向输入来运行bash脚本的Command()
- 在输入时重定向按javascript(但表单是硬连接到插件中的,所以必须使用输入类而不是ID)
- 在页面重定向到另一个页面后输入凭据
- javascript在文本框中输入键重定向
- 重定向具有多个提交输入的表单