我获得了一堆代码(PHP),但没有很好地记录;那说,我有一些对我没有任何意义的形式逻辑。这是页面html代码:
<?php
session_start();
ini_set('display_errors', 1);
error_reporting(E_ALL);
$itemcount = isset($_SESSION['itemcount']) ? $_SESSION['itemcount'] : 0;
if ($itemcount == 0)
{
header("Location: "."error.php?msg=".rawurlencode("Please add items to your shopping cart before checking out."));
exit;
}
if (!isset($_SESSION['email']))
{
header("Location: "."error.php?msg=".rawurlencode("We did not find your information, please fill the needed information again."));
exit;
}
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$_SESSION['shipname'] = $_POST['shipname'];
$_SESSION['shipaddress'] = $_POST['shipaddress'];
$_SESSION['shipzip'] = $_POST['shipzip'];
$_SESSION['shipcity'] = $_POST['shipcity'];
$_SESSION['shipstate'] = $_POST['shipstate'];
$_SESSION['shipcountry'] = $_POST['shipcountry'];
$_SESSION['paymenttype'] = $_POST['paymenttype'];
$_SESSION['cardname'] = $_POST['cardname'];
$_SESSION['cardno'] = $_POST['cardno'];
$_SESSION['cardmonth'] = $_POST['cardmonth'];
$_SESSION['cardyear'] = $_POST['cardyear'];
header("Location: "."thankyou.php");
}
$shipname = isset($_SESSION['shipname']) ? $_SESSION['shipname'] : '';
$shipaddress = isset($_SESSION['shipaddress']) ? $_SESSION['shipaddress'] : '';
$shipzip = isset($_SESSION['shipzip']) ? $_SESSION['shipzip'] : '';
$shipcity = isset($_SESSION['shipcity']) ? $_SESSION['shipcity'] : '';
$shipstate = isset($_SESSION['shipstate']) ? $_SESSION['shipstate'] : '';
$shipcountry = isset($_SESSION['shipcountry']) ? $_SESSION['shipcountry'] : '';
$cardname = isset($_SESSION['cardname']) ? $_SESSION['cardname'] : '';
$cardno = isset($_SESSION['cardno']) ? $_SESSION['cardno'] : '';
?>
这是表单html:
<div id="wb_checkout" style="position:absolute;width:957px; height:374px;">
<form name="checkout" method="post" action="checkout.php" id="checkout">
<div id="wb_Text3" style="position:absolute;left:32px;top:88px;width:88px;height:34px;z-index:36;">
<div style="font-family:Arial;font-size:13px;color:#000000;">
<div><span style="font-family:Verdana;font-size:16px;">Address: </span> </div>
</div>
</div>
<div id="wb_Text5" style="position:absolute;left:32px;top:138px;width:61px;height:34px;z-index:37;">
<div style="font-family:Arial;font-size:13px;color:#000000;">
<div><span style="font-family:Verdana;font-size:16px;">City:</span> </div>
</div>
</div>
<div id="wb_Text6" style="position:absolute;left:32px;top:193px;width:88px;height:42px;z-index:38;">
<div style="font-family:Arial;font-size:13px;color:#000000;">
<div><span style="font-family:Verdana;font-size:16px;">Zip Code:</span></div>
</div>
</div>
<div id="wb_Text7" style="position:absolute;left:294px;top:195px;width:74px;height:34px;z-index:39;">
<div style="font-family:Arial;font-size:13px;color:#000000;">
<div><span style="font-family:Verdana;font-size:16px;">State:</span> </div>
</div>
</div>
<div id="wb_Text4" style="position:absolute;left:32px;top:37px;width:88px;height:34px;z-index:40;">
<div style="font-family:Arial;font-size:13px;color:#000000;">
<div><span style="font-family:Verdana;font-size:16px;">Name:</span> </div>
</div>
</div>
<input type="text" id="Editbox1" style="position:absolute;left:125px;top:85px;width:412px;height:34px;line-height:34px;z-index:41;" name="shipaddress" value="">
<input type="text" id="Editbox3" style="position:absolute;left:99px;top:137px;width:412px;height:34px;line-height:34px;z-index:42;" name="shipcity" value="">
<input type="text" id="Editbox4" style="position:absolute;left:373px;top:195px;width:65px;height:34px;line-height:34px;z-index:43;" name="shipstate" value="">
<input type="text" id="Editbox2" style="position:absolute;left:124px;top:36px;width:412px;height:34px;line-height:34px;z-index:44;" name="shipname" value="">
<input type="text" id="Editbox5" style="position:absolute;left:125px;top:194px;width:117px;height:34px;line-height:34px;z-index:45;" name="shipzip" value="">
<input type="submit" id="Button1" name="submitOrder" value="Submit Order" style="position:absolute;left:612px;top:317px;width:110px;height:36px;z-index:46;">
<input type="submit" id="Button2" name="cancelOrder" value="Cancel Order" style="position:absolute;left:761px;top:318px;width:114px;height:35px;z-index:47;">
</form>
</div>
问题是该页面没有呈现;它只是跳到下一页(thankyou.php)而没有显示表单,因此用户可以输入发货信息。此外,根据作者使用的逻辑,我看不到送货信息将如何进入下一页,因为它之前有一个标题声明。最后,我没有看到处理提交订单或取消订单的任何逻辑。
我是PHP的菜鸟,但学习速度快;我已经编程很长很长时间了,这没有任何意义。有人可以告诉我:
答案 0 :(得分:1)
更好的方法是使用它:
if(isset($_POST['submitOrder']))
而不是:
if($_SERVER['REQUEST_METHOD'] == 'POST')
&#34;提交订单&#34;按钮只有在点击的按钮才会被设置。