如果我硬编码$ dest_zip它工作正常,但如果我将它设置为$ _POST ['zipcode'],当我在我的发货页面上回显会话变量时,它会显示“0”。
为什么我得到0而不是未定义或错误的任何想法?它使调试变得困难。我有一种感觉,这是因为我试图将帖子数据发送到两个单独的文件。(我需要记录和处理信息)
提前感谢您的帮助。
address.php
Choose a recent address:
<form action="javascript:callPHP()" method="post">
<?php
error_reporting(E_ALL);
session_start();
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "secure_login";
$username=$_SESSION['login_user'];
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT first_name, last_name, address, city, state, zip FROM address
WHERE username = '$username'";
$result = $conn->query($sql);
if (!$result) {
trigger_error('Invalid query: ' . $conn->error);
}
if ($result->num_rows > 0) {
// output data of each row
echo "<select required name='zipcode'>";
while($row = $result->fetch_assoc()) {
echo "<option value=" . $row['zip'] .">".$row['first_name'].'-'.
$row['last_name'] .'-'. $row['address'].'-'.$row['city'].'-'.$row['state'].'-
'.$row['zip']."</option>";
//$i++;
}
} else {
echo "<option value=''> No address on file </option>";
}
echo "</select>";
?>
<input type="checkbox" name="active" value="1"> Make default shipping
location<br>
<input type="submit" onclick="window.location.href = 'cart/shipping.php';"
value="Quote Shipping">
</form>
<script>
function callPHP(){
$.post( "addressdb.php", function( data ) {
// handle data from formProcess.php
});
$.post( "cart/3dbinpack/3DBP.php", function( data ) {
// handle data from Portal.php
});
}
</script>
来自3DBP.php的片段:
$dest_zip = $_POST['zipcode'] ?? '';
然后在一些API中使用了更多的代码,最后我将它们的结果设置为一个会话变量,我在shipping.php页面上回应。