0

如果用户没有填写个人信息或购物订单,我正试图让网页提醒用户......它没有做我想做的事情......我认为这可能是因为我使用了 php一个和另一个 javascript..

个人信息.php

<?php 
    if(isset($_COOKIE['name'])) {

        $name = $_COOKIE['name'];
        $email = $_COOKIE['email'];
        $address = $_COOKIE['address'];
        $phone = $_COOKIE['phone'];
        $credit = $_COOKIE['credit'];
        $expire = $_COOKIE['expire'];
        $cvs = $_COOKIE['cvs']; 
    }

?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Personal Info</title>
    <link href="general.css" type="text/css" rel="stylesheet" />
    <script type="text/javascript" src="general.js" />
    </script>
</head>

<body>
    <div>
    <div id="sidebar">
        <div style="color:#CCC">
            <h2><a href="index.html">James' NBA Jersey Shop</a></h2>
        </div>
        <div>
        <FORM>
            <p><INPUT Type="BUTTON" VALUE="Personal Info" ONCLICK="window.location.href='personalInfo.php'" /></p> 
            <p><INPUT Type="BUTTON" VALUE="Jersey Collection" ONCLICK="window.location.href='jerseyCollection.php'" /></p>
            <p><INPUT Type="BUTTON" VALUE="Confirmation" ONCLICK="window.location.href='confirmation.php'" disabled /></p>
            <p><INPUT Type="BUTTON" VALUE="Order" ONCLICK="window.location.href='order.html'" /></p>
            <br>
            <p><INPUT Type="reset" VALUE="Reset Order Info" /></p>
            <br>
            <br>
            <p>Web Style Option</p>
            <p><input name ="stylish" value="DGH" onclick="styleChange('DGH')" type="radio" checked="true" />Dark Gray & Gray & Helvetica</p> 
            <p><input name ="stylish" value="RON" onclick="styleChange('RON')" type="radio" />Red & Orange & New York</p>  
            <p><input name ="stylish" value="SBC" onclick="styleChange('SBC')" type="radio" />Sky Blue & Blue & Comic Sans</p> 

        </FORM>
        </div>
    </div>



    <div id="contents">
        <div>
            <h1 class="title">Personal Information</h1>      
        </div>


                <form action="http://i6.cims.nyu.edu/~jwj243/Assignment5/jerseyCollection.php"  method="post">
                <p>
                Name: <br>
                <input type = "text" name = "name" id="name" value = <?php if (isset($_COOKIE['name'])) echo $name; ?>>
                </p>
                <p>
                Email address: <br>
                <input type = "text" name = "email" id="email" value = <?php if (isset($_COOKIE['email'])) echo $email; ?>>
                </p> 
                <p> 
                Shipping address: <br>
                <input type = "text" name = "address" id="address" value = <?php if (isset($_COOKIE['address'])) echo $address; ?>>
                </p>
                <p>
                Phone Number(without '-'): <br>
                <input type = "text" name = "phone" id="phone" value = <?php if (isset($_COOKIE['phone'])) echo $phone; ?>>
                </p>

                <h2 style="font-size:24px">Payment Information</h2>

                <p>
                Credit Card Number: <br>
                <input type = "text" name = "credit" id="credit" value = <?php if (isset($_COOKIE['credit'])) echo $credit; ?>>
                </p>
                <p>Expiration date(yy/mm): <br>
                <input type = "text" name = "expire" id="expire" value = <?php if (isset($_COOKIE['expire'])) echo $expire; ?>>
                </p>
                <p>
                CVS Number(Last 3-digit number): <br>
                <input type ="text" name = "cvs" id="cvs" value = <?php if (isset($_COOKIE['cvs'])) echo $cvs; ?>>
                </p>



                <input type= "submit" value= "Next, Jersey Selection" /><p>
                <input type="hidden" name="submitted" value="true" />
                <input type= "reset" value= "Cancel">

                </form>



    <br/><br/><br/><br/><br/><br/><br/>


    </div>
</div>
</body>
</html>

确认.php

<?php

session_start();

$cName = $_SESSION['cName'];
$cEmail = $_SESSION['cEmail'];
$cAddress = $_SESSION['cAddress'];
$cPhone = $_SESSION['cPhone'];
$cCredit = $_SESSION['cCredit'];
$cExpire = $_SESSION['cExpire'];
$cCvs = $_SESSION['cCvs'];

if (isset($_POST['submitted'])) {


    $PROD_ajs_20 = $_POST['PROD_ajs_20'];
    $PROD_bpp_25 = $_POST['PROD_bpp_25'];
    $PROD_bdw_25 = $_POST['PROD_bdw_25'];
    $PROD_cdr_30 = $_POST['PROD_cdr_30'];
    $PROD_hjl_25 = $_POST['PROD_hjl_25'];
    $PROD_lbg_30 = $_POST['PROD_lbg_30'];
    $PROD_lkb_30 = $_POST['PROD_lkb_30'];
    $PROD_mdw_30 = $_POST['PROD_mdw_30'];
    $PROD_mlj_35 = $_POST['PROD_mlj_35'];
    $PROD_nca_35 = $_POST['PROD_nca_35'];
    $PROD_okd_35 = $_POST['PROD_okd_35'];
    $PROD_odh_30 = $_POST['PROD_odh_30'];   

    $realTotal = $_POST['realTotal'];

    setcookie('PROD_ajs_20',$PROD_ajs_20, time() + 5*60);
    setcookie('PROD_bpp_25',$PROD_bpp_25, time() + 5*60);
    setcookie('PROD_bdw_25',$PROD_bdw_25, time() + 5*60);
    setcookie('PROD_cdr_30',$PROD_cdr_30, time() + 5*60);
    setcookie('PROD_hjl_25',$PROD_hjl_25, time() + 5*60);
    setcookie('PROD_lbg_30',$PROD_lbg_30, time() + 5*60);
    setcookie('PROD_lkb_30',$PROD_lkb_30, time() + 5*60);
    setcookie('PROD_mdw_30',$PROD_mdw_30, time() + 5*60);
    setcookie('PROD_mlj_35',$PROD_mlj_35, time() + 5*60);
    setcookie('PROD_nca_35',$PROD_nca_35, time() + 5*60);
    setcookie('PROD_okd_35',$PROD_okd_35, time() + 5*60);
    setcookie('PROD_odh_30',$PROD_odh_30, time() + 5*60);

    setcookie('realTotal', $realTotal, time() + 5*60);
} 

if((!isset($_COOKIE['name'])) ||
    !isset($_COOKIE['email']) ||
    !isset($_COOKIE['address'])||
    !isset($_COOKIE['phone'])||
    !isset($_COOKIE['credit'])||
    !isset($_COOKIE['expire'])||
    !isset($_COOKIE['cvs'])){
        echo ("<SCRIPT LANGUAGE='JavaScript'>
            window.alert('Please fill in the Personal Information Page, first')
            window.location.href='personalInfo.php';
            </SCRIPT>");
}
/*
elseif (!isset($_COOKIE['realTotal'])){
        echo ("<SCRIPT LANGUAGE='JavaScript'>
            window.alert('Please shop from Jersey Collection page!')
            window.location.href='jerseyCollection.php';
            </SCRIPT>");        
}
*/
?>

<HTML>
<head>
<title>Confirmation</title>
    <link href="general.css" type="text/css" rel="stylesheet" />
    <script type="text/javascript" src="general.js" />
    </script>

</head>
<body>
    <div>
        <div id="sidebar">
        <div style="color:#CCC">
            <h2><a href="index.html">James' NBA Jersey Shop</a></h2>
        </div>
        <div>
        <FORM>
            <p><INPUT Type="BUTTON" VALUE="Personal Info" ONCLICK="window.location.href='personalInfo.php'" /></p> 
            <p><INPUT Type="BUTTON" VALUE="Jersey Collection" ONCLICK="window.location.href='jerseyCollection.php'" disabled /></p>
            <p><INPUT Type="BUTTON" VALUE="Confirmation" ONCLICK="window.location.href='confirmation.php'" disabled /></p>
            <p><INPUT Type="BUTTON" VALUE="Order" ONCLICK="window.location.href='order.html'" /></p>
            <br>
            <p><INPUT Type="reset" VALUE="Reset Order Info" /></p>
            <br>
            <br>
            <p>Web Style Option</p>
            <p><input name ="stylish" value="DGH" onClick="styleChange('DGH')" type="radio" checked="true" />Dark Gray & Gray & Helvetica</p> 
            <p><input name ="stylish" value="RON" onClick="styleChange('RON')" type="radio" />Red & Orange & New York</p>  
            <p><input name ="stylish" value="SBC" onClick="styleChange('SBC')" type="radio" />Sky Blue & Blue & Comic Sans</p> 

        </FORM>
        </div>
    </div>

       <div id="contents">
        <div>
            <h1 class="title">Confirmation</h1>      
        </div>
            <h2>Hello, <?php print $_COOKIE['name']; ?>! </h2>

            <H3> Confirmation </h3>

             <h2> Your Order </h2>
                <ul>
                    <li>Your Email Address: <?php print $_COOKIE['email']; ?>
                    <li>Your Address: <?php print $_COOKIE['address']; ?>
                    <li>Your Phone Number: <?php print $_COOKIE['phone']; ?>
                    <li>Your choice of the Jersey: 
                    <li>Quantity:
                    <li>Total Price: <?php print $_POST['realTotal'] ?>
                </ul>
         <br/><br/><br/><br/><br/><br/><br/>
        </div>
 </html>

</body>
</html>

泽西系列

<?php 

session_start();
$_SESSION['cName'] = $_POST['name'];
$_SESSION['cEmail'] = $_POST['email'];
$_SESSION['cAddress'] = $_POST['address'];
$_SESSION['cPhone'] = $_POST['phone'];
$_SESSION['cCredit'] = $_POST['credit'];
$_SESSION['cExpire'] = $_POST['expire'];
$_SESSION['cCvs'] = $_POST['cvs'];

/*
$cName = $_SESSION['cName'];
$cEmail = $_SESSION['cEmail'];
$cAddress = $_SESSION['cAddress'];
$cPhone = $_SESSION['cPhone'];
$cCredit = $_SESSION['cCredit'];
$cExpire = $_SESSION['cExpire'];
$cCvs = $_SESSION['cCvs'];
*/

if(isset($_POST['submitted'])) {

    $name = $_POST['name'];
    $email = $_POST['email'];
    $address = $_POST['address'];
    $phone = $_POST['phone'];
    $credit = $_POST['credit'];
    $expire = $_POST['expire'];
    $cvs = $_POST['cvs'];

    setcookie('name',$name, time() + 5*60);
    setcookie('email',$email, time() + 5*60);
    setcookie('address',$address, time() + 5*60);
    setcookie('phone',$phone, time() + 5*60);
    setcookie('credit',$credit, time() + 5*60);
    setcookie('expire',$expire, time() + 5*60);
    setcookie('cvs',$cvs, time() + 5*60);

} 

if(isset($_COOKIE['name'])) {

        $PROD_ajs_20 = $_COOKIE['PROD_ajs_20'];
        $PROD_bpp_25 = $_COOKIE['PROD_bpp_25'];
        $PROD_bdw_25 = $_COOKIE['PROD_bdw_25'];
        $PROD_cdr_30 = $_COOKIE['PROD_cdr_30'];
        $PROD_hjl_25 = $_COOKIE['PROD_hjl_25'];
        $PROD_lbg_30 = $_COOKIE['PROD_lbg_30'];
        $PROD_lkb_30 = $_COOKIE['PROD_lkb_30'];
        $PROD_mdw_30 = $_COOKIE['PROD_mdw_30'];
        $PROD_mlj_35 = $_COOKIE['PROD_mlj_35'];
        $PROD_nca_35 = $_COOKIE['PROD_nca_35'];
        $PROD_okd_35 = $_COOKIE['PROD_okd_35'];
        $PROD_odh_30 = $_COOKIE['PROD_odh_30'];

        $realTotal = $_COOKIE['realTotal'];     


    }

/*
$collection = array('Josh Smith' => array(20, 'atlanta_josh_smith.jpg'),
                    'Paul Pierce' => array(25, 'boston_paul_pierce.jpg'),
                    'Deron Williams' => array(25, 'brooklyn_deron_williams.jpg'),
                    'Derrick Rose' => array(30, 'chicago_derrick_rose.jpg'),
                    'Jeremy Lin' => array(25, 'houston_jeremy_lin.jpg'),
                    'Blake Griffin' => array(30, 'la_blake_griffin.jpg'),
                    'Kobe Bryant' => array(30, 'la_kobe_bryant.jpg'),
                    'Dwyane Wade' => array(30, 'miami_dwyane_wade.jpg'),
                    'Lebron James' => array(35, 'miami_lebron_james.jpg'),
                    'Carmelo Anthony' => array(35, 'ny_carmelo_anthony.jpg'),
                    'Kevin Durant' => array(35, 'okc_kevin_durant.jpg'),
                    'Dwight Howard' => array(30, 'orlando_dwight_howard.jpg'),
                    )
*/


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Jersey Collection</title>
    <link href="general.css" type="text/css" rel="stylesheet" />
    <style type="text/css">
        table {
                border: 4px solid #333333; 
                width: 80%;    
                margin-left: auto;
                margin-right: auto; }
        td {
                padding: 8px;
                border 1px solid #333333;
                background-color: #ccc; 
                text-align: center; }
    </style>
    <script type="text/javascript" src="general.js" />
    </script>
</head>
<body>
       <div>
        <div id="sidebar">
                <div style="color:#CCC">
                    <h2><a href="index.html">James' NBA Jersey Shop</a></h2>
                </div>
                <div>
                <FORM>
                    <p><INPUT Type="BUTTON" VALUE="Personal Info" ONCLICK="window.location.href='personalInfo.php'" /></p> 
                    <p><INPUT Type="BUTTON" VALUE="Jersey Collection" ONCLICK="window.location.href='jerseyCollection.php'" disabled /></p>
                    <p><INPUT Type="BUTTON" VALUE="Confirmation" ONCLICK="window.location.href='confirmation.php'" disabled /></p>
                    <p><INPUT Type="BUTTON" VALUE="Order" ONCLICK="window.location.href='order.html'" /></p>
                    <br>
                    <p><INPUT Type="reset" VALUE="Reset Order Info" /></p>
                    <br>
                    <br>
                    <p>Web Style Option</p>
                    <p><input name ="stylish" value="DGH" onclick="styleChange('DGH')" type="radio" checked="true" />Dark Gray & Gray & Helvetica</p> 
                    <p><input name ="stylish" value="RON" onclick="styleChange('RON')" type="radio" />Red & Orange & New York</p>  
                    <p><input name ="stylish" value="SBC" onclick="styleChange('SBC')" type="radio" />Sky Blue & Blue & Comic Sans</p> 

                </FORM>
                </div>
            </div>
    <div id="contents">
        <div>
            <h1 class="title">Jersey Collection</h1>      
        </div>
        <form name="choice" action="http://i6.cims.nyu.edu/~jwj243/Assignment5/confirmation.php" method="post">
        <table align="center">
            <tr>
                <td><img src="atlanta_josh_smith.jpg" width="200" height="200"/></td>
                <td><img src="boston_paul_pierce.jpg" width="200" height="200"/></td>
                <td><img src="brooklyn_deron_williams.jpg" width="200" height="200"/></td>
                <td><img src="chicago_derrick_rose.jpg" width="200" height="200"/></td>
            </tr>
            <tr>
                <td>Price: $20<br>Quantity<input name="PROD_ajs_20" id="q" size=2 type="text" onChange = "calculateTotal(this.form)" value= 
                <?php if(isset($_COOKIE['name'])) echo $PROD_ajs_20; else echo 0;  ?> ></td>
                <td>Price: $25<br>Quantity<input name="PROD_bpp_25" id="q" size=2 type="text" onChange = "calculateTotal(this.form)" value=
                <?php if(isset($_COOKIE['name'])) print $PROD_bpp_25; else echo 0;  ?> ></td>
                <td>Price: $25<br>Quantity<input name="PROD_bdw_25" id="q" size=2 type="text" onChange = "calculateTotal(this.form)" value=
                <?php if(isset($_COOKIE['name'])) print $PROD_bdw_25; else echo 0; ?> ></td>
                <td>Price: $30<br>Quantity<input name="PROD_cdr_30" id="q" size=2 type="text" onChange = "calculateTotal(this.form)" value=
                <?php if(isset($_COOKIE['name'])) print $PROD_cdr_30; else echo 0; ?> ></td>
            </tr>
            <tr>
                <td><img src="houston_jeremy_lin.jpg" width="200" height="200"/></td>
                <td><img src="la_blake_griffin.jpg" width="200" height="200"/></td>
                <td><img src="la_kobe_bryant.jpg" width="200" height="200"/></td>
                <td><img src="miami_dwyane_wade.jpg" width="200" height="200"/></td>
            </tr>
            <tr>
                <td>Price: $25<br>Quantity<input name="PROD_hjl_25" id="q" size=2 type="text" onChange = "calculateTotal(this.form)" value=
                <?php if(isset($_COOKIE['name'])) echo $PROD_hjl_25; else echo 0; ?>  ></td>
                <td>Price: $30<br>Quantity<input name="PROD_lbg_30" id="q" size=2 type="text" onChange = "calculateTotal(this.form)" value=
                <?php if(isset($_COOKIE['name'])) echo $PROD_lbg_30; else echo 0; ?>  ></td>
                <td>Price: $30<br>Quantity<input name="PROD_lkb_30" id="q" size=2 type="text" onChange = "calculateTotal(this.form)" value=
                <?php if(isset($_COOKIE['name'])) echo $PROD_lkb_30; else echo 0; ?>  ></td>
                <td>Price: $30<br>Quantity<input name="PROD_mdw_30" id="q" size=2 type="text" onChange = "calculateTotal(this.form)" value=
                <?php if(isset($_COOKIE['name'])) echo $PROD_mdw_30; else echo 0; ?>  ></td>
            </tr>
            <tr>
                <td><img src="miami_lebron_james.jpg" width="200" height="200"/></td>
                <td><img src="ny_carmelo_anthony.jpg" width="200" height="200"/></td>
                <td><img src="okc_kevin_durant.jpg" width="200" height="200"/></td>
                <td><img src="orlando_dwight_howard.jpg" width="200" height="200"/></td>
            </tr>
            <tr>
                <td>Price: $35<br>Quantity<input name="PROD_mlj_35" id="q" size=2 type="text" onChange = "calculateTotal(this.form)" value=
                <?php if(isset($_COOKIE['name'])) echo $PROD_mlj_35; else echo 0; ?>  ></td>
                <td>Price: $35<br>Quantity<input name="PROD_nca_35" id="q" size=2 type="text" onChange = "calculateTotal(this.form)" value=
                <?php if(isset($_COOKIE['name'])) echo $PROD_nca_35; else echo 0; ?>  ></td>
                <td>Price: $35<br>Quantity<input name="PROD_okd_35" id="q" size=2 type="text" onChange = "calculateTotal(this.form)" value=
                <?php if(isset($_COOKIE['name'])) echo $PROD_okd_35; else echo 0; ?>  ></td>
                <td>Price: $30<br>Quantity<input name="PROD_odh_30" id="q" size=2 type="text" onChange = "calculateTotal(this.form)" value=
                <?php if(isset($_COOKIE['name'])) echo $PROD_odh_30; else echo 0; ?>  ></td>

            </tr>            

        </table>
        <div>
            <table>
                <tr>
                    <td>Total: <input type="text" id ="realTotal" name="realTotal" size=2 value = <?php if(isset($_COOKIE['name'])) echo $realTotal; ?> ></td>
                    <td><span name="order_total" id="order_total" style="text-align: right; font-size: 20px">$0.00</span></td>
                </tr>
                <tr>
                    <td><input type= "submit" value="Next" onClick="return checkOrder()" ><input type="hidden" name="submitted" value ="true" /></td>
                    <td></td>
                </tr>
            </table>
        </div>
        </form>
     <br/><br/><br/><br/><br/><br/><br/>   
    </div>
</div>
</body>
</html>
4

1 回答 1

0

使用cookiesOR sessions。我发现在此示例中使用 cookie 会更好一些,但您可以将其应用于您的任何需求。

Jersey Collection我看到你正在使用sessions

$_SESSION['cName'] = $_POST['name'];
$_SESSION['cEmail'] = $_POST['email'];
$_SESSION['cAddress'] = $_POST['address'];
$_SESSION['cPhone'] = $_POST['phone'];
$_SESSION['cCredit'] = $_POST['credit'];
$_SESSION['cExpire'] = $_POST['expire'];
$_SESSION['cCvs'] = $_POST['cvs'];

我建议使用这样的cookie:

setcookie("name",$_POST['name']);
setcookie("email",$_POST['email']);
setcookie("address",$_POST['address']);
setcookie("phone",$_POST['phone']);
setcookie("credit",$_POST['credit']);
setcookie("expire",$_POST['name']);
setcookie("cvs",$_POST['cvs']);

然后看着Personal Info.php

$name = $_COOKIE['name'];
$email = $_COOKIE['email'];
$address = $_COOKIE['address'];
$phone = $_COOKIE['phone'];
$credit = $_COOKIE['credit'];
$expire = $_COOKIE['expire'];
$cvs = $_COOKIE['cvs'];

这更有意义。

于 2013-05-07T05:32:05.060 回答