我有两个不同的文件。
Checkoutstep4.php
Checkoutstep5.php
提交第一个表单时,我想获取已提交的'country'的值,并在IF函数中使用它:
这是我到目前为止使用的会话变量... 但我得到一个错误说未定义的索引,我不知道为什么。
checkoutDeliveryInfo(提交投放详细信息表单时运行的文件)。
<?php
session_start();
require_once 'DatabaseConnection.php';
$_SESSION['customerid'];
if (isset($_POST['submit'])) {
$stmt = $pdo->prepare("INSERT INTO DeliveryDetails (customerid,firstname,lastname, addressline1, addressline2, city, county, country, postalcode)
VALUES ({$_SESSION['customerid']}, :firstname, :lastname, :addressline1, :addressline2, :city, :county, :country, :postalcode)");
$stmt->bindParam(':firstname', $firstname);
$stmt->bindParam(':lastname', $lastname);
$stmt->bindParam(':addressline1', $addressline1);
$stmt->bindParam(':addressline2', $addressline2);
$stmt->bindParam(':city', $city);
$stmt->bindParam(':county', $county);
$stmt->bindParam(':country', $country);
$stmt->bindParam(':postalcode', $postalcode);
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$addressline1 = $_POST['addressline1'];
$addressline2 = $_POST['addressline2'];
$city = $_POST['city'];
$county = $_POST['county'];
$country = $_POST['country'];
$postalcode = $_POST['postalcode'];
$stmt->execute();
$_SESSION['country'] = $country;
header('location:../View/php_shopping_cart/CheckoutStep5.php');
}
正在使用会话变量的Checkoutstep5.php文件中的IF函数:
<?php
include '../../Model/ShoppingCart.php';
$shoppingCart = new ShoppingCart;
// redirect to home if cart is empty
if ($shoppingCart->total_items() <= 0) {
header("Location: ../index.php");
}
?>
<div class="shippingcost"><strong>Shipping Cost <?php
if ($_SESSION['country'] != 'GIB') {
$shippingcost = '10.00';
} else {
$shippingcost = 'FREE';
}
echo $shippingcost;
?></strong>
</div>
感谢任何帮助。
更新:错误消息:
注意:未定义的索引:246行/home/k1509759/www/barbarycoast/View/php_shopping_cart/CheckoutStep5.php中的国家/地区
答案 0 :(得分:0)
我设法通过从会话中提取所有变量然后使用我想要的个人来完成它。
extract($_SESSION);
if ($country == 'GIB') {
$shippingcost = 'FREE';
} else if ($country == 'GBR') {
$shippingcost = '£10.00';
} else if ($country == 'ESP') {
$shippingcost = '£10.00';
}