我有一个分段标记,根据用户点击page1.php
中的包的内容来更新其值。即没有选择,部分标签中没有任何内容,用户现在选择包1作为包标签,因为包1.但是当我使用php POST
它并检查它是否设置它是不是有一个原因是什么?
我希望设置POST_['foodchoice']
,以便我可以在page2.php
中有一个部分,我可以在其中总结用户选择的包。
有点像购物车功能,但没有数据库,数量选择等。 请告知原因。感谢
page1.php中
<script type ="text/javascript">
function changemyButton()
{
var elem = document.getElementById("button3");
if (elem.value == "Un-Select Package")
elem.value = "Select This Package";
else if( elem.value == "Package Selected!" ) {
elem.value = "Select This Package";
elem.style.background = "#003e7e";
document.getElementById("selection").innerHTML = '';
} else {
elem.value = "Package Selected!";
elem.style.background = "green";
document.getElementById("selection").innerHTML = '1x The Share Collection';
}
}
</script>
<h1 id="logo"> Breakfast Menu Options </h1></section>
<hr>
</br>
<center>
<form action="homePage.php" method="post" onsubmit="">
<center>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"> </script>
<div class= "breakfast">
<u><h2>The Share Collection</h2></u>
</br>
<img src= "\images\Breakfast\breakfast1.jpg" class="funky">
</br>
</br>
<dl>
<dd>Mini jar of housemade granola: vanilla yoghurt, fresh fruit (v) (6)</dd>
<dd>Goat cheese, cherry tomato & basil, mushroom tart (v) (8)</dd>
<dd>Mini slider jamon serrano, fig jam, rocket, brie & black pepper (8) </dd>
<dd>Chef's mini sweet muffin (v) (8)</dd>
<dd>Bowl of strawberries & grapes (v) (1)</dd>
</dl>
</br>
<input type='button' value='Select This Package' id='button3' onclick="changemyButton()">
<hr>
<section id="myform">
<h1 id="logo">Total Ordered</h1></section>
<hr>
</br>
<section id ="selection" name="foodchoice"></section>
<br>
<br>
<br>
<br>
<input type="button" id="button4" value="Submit Your Selection" name="submit" onclick="window.location='homePage.php';" >
</div>
</center>
</form>
</div>
</div>
第2.pp页
<?php
session_start();
error_reporting( E_ALL & ~E_NOTICE );
if (!isset($_SESSION['time'])) {
header("Location: openingPage.php");
exit();
}
if (isset($_POST['foodchoice']))
{
echo "yay!";
}
if (!isset($_POST['foodchoice']))
{
echo "nay!";
}
?>
然后在我的html体内,我会:
<div id ="packageselected">
<?php echo $_POST['foodchoice']; ?>
</div>