这是food.php的页面,它将链接到order.php以将订单添加到购物车中。
<input type="hidden" name="id" value="<?php echo $row["foodID"];?>" />
<dt>
<img src="<?php echo $row["food_img"];?>" />
<input name="img" type="hidden" class="img" value="<?php echo $row["food_img"];?>" /> </dt>
<dd>
<form action="order.php" method="get" name="send" onSubmit="return Check()" enctype="multipart/form-data">
<h3><?php echo $row["food_name"];?>
<input name="name" type="hidden" class="name" value="<?php echo $row["food_name"];?>" /></h3>
<div class="detailtips">
<?php echo $row["food_description"];?>
</div>
<p><span>Restaurant:</span><strong><?php echo $row["restaurant_name"];?>
<input name="restaurant" type="hidden" class="restaurant" value="<?php echo $row["restaurant_name"];?>" />
</strong></p>
<p><span>Type :</span><strong><?php echo $row["food_type"];?></strong></p>
<input name="num" type="hidden" class="num" value="<?php echo $row["order_num"];?>" />
<p><span>Price :</span>RM <strong><?php echo $row["food_price"];?>
<input name="price" type="hidden" class="price" value="<?php echo $row["food_price"];?>" /></strong></p>
<div class="order" style=" padding-top:20px; padding-left:20px;">
<input name="" type="submit" value="" class="ordersubmit" style=" margin-left:30px; margin-top:20px;">
</div>
</form>
这是order.php
<?php session_start();
ini_set('error_reporting', 'E_ALL ^ E_NOTICE');
header("Content-type: text/html; charset=utf-8");
include("conn.php");
$action = $_GET['action'];
$user = $_SESSION['username'];
foreach ($_GET AS $key=>$value)
{
$key ;
}
$nameid=substr($key,4);
$namenum=$_GET[$key];
if($namenum){
$arr = mysql_query("select * from ordering where id='$nameid'");
$rowres = mysql_fetch_array($arr);
$total=$rowres['food_price']*$namenum;
$sqlup="update ordering SET order_num='$namenum', total='$total' where id='$nameid'" ;
$rus = mysql_query($sqlup);
}
if(empty($user)){
echo "<script>alert('No login, please log in!');window.location='Log In.php';</script>";
exit;
}
$orderID = $_GET['id'];
$food_img = $_GET['img'];
$food_name = $_GET['name'];
$restaurant_name = $_GET['restaurant'];
$food_price = $_GET['price'];
$order_num = $_GET['num'];
$total=$food_price*$order_num;
if($action == 'add'){
$arr = mysql_query("select * from ordering where id='$orderID'");
$rowres = mysql_fetch_array($arr);
$row=mysql_num_rows($arr);
if($row>0){$ordernum=$rowres['order_num'];
$t_price=$rowres['food_price'];
$ordernum=$ordernum+$order_num;
$t_pricea=$t_price*$ordernum;
$sql="update ordering set order_num='$ordernum', total='$t_pricea' where id='$orderID' ";
$resulta = mysql_query($sql);
if($resulta==true)
{
echo "<script>alert('success');window.location.href='order.php'</script>";
}
}else{
$sqlin="INSERT INTO ordering (`id`,`orderID`,`food_img`,`food_name`,`restaurant_name`,`food_price`,`total`,`order_num`,`username`,`time`) VALUES('','$orderID','$food_img','$food_name','$restaurant_name','$food_price','$total','$order_num','$user',now()) ";
$rus = mysql_query($sqlin);
if($rus==true)
{
echo "<script>alert('success');window.location.href='order.php'</script>";
}
}
}
?>
<?PHP
if($action=="delcar"){
$delid=$_POST['delcar'];
$pieces = explode(",", $delid);
if($pieces==""){
echo "<script language=\"javascript\">alert('please choose!');window.location.href='order.php'</script>";die;
}
$arrayLen = sizeof( $pieces );
for( $i = 0; $i< $arrayLen ;$i++ )
{
$sql="delete from ordering where id='$pieces[$i]'";
$result=mysql_query($sql); }
if($result==true)
{
echo "<script language=\"javascript\">alert('del success!');window.location.href='order.php'</script>";die;
}else{
echo "<script language=\"javascript\">alert('del failed, please re-enter!');window.location.href='order.php'</script>";die;
}
}
?>
这是链接到orderlist.php的表单
<div class="shopbox">
<form method="get" action="orderlist.php" id="shopcarall" >
<input type="hidden" name="action" value="change" />
<div class="shopmain">
<ul><li style="padding:30px 10px 0 0"><input name="chackcar[]" type="checkbox" class="userid" value="<?php echo $row['id']?>" /></li>
<li class="boxa"> <img src="<?php echo $row['food_img'];?>" width="130" height="98"> </li>
<li class="boxb">
<h3>Food name</h3>
<h4><?php echo $row['food_name'];?> </h4>
</li>
<li class="boxc">
<h3>Restaurant</h3>
<h4> <?php echo $row['restaurant_name']; ?> </h4>
</li>
<li class="boxc">
<h3>Food price</h3>
<h4> <?php echo $row['food_price']; ?> </h4>
</li>
<li class="boxc">
<h3>Order num</h3>
<h4>
<a class="del" href="javascript:void(0)"> - </a><input type="text" name="<?php echo $row['id']; ?>" class="inputcss" value="<?php echo $row['order_num']; ?>" style=" margin:0; float:left">
<a class="add" href="javascript:void(0)"> + </a>
</h4>
</li>
<li class="boxc">
<h3>Total</h3>
<h4>RM <?php echo $row['total'];?></h4>
</li>
</ul>
</div>
</form>
为什么food.php中的价值我无法获得order.php? 我的编码有什么不对吗? 由于输入的名称与$ _GET [&#39;&#39;]匹配,我仍然不知道为什么数据没有显示?
答案 0 :(得分:0)
<?php
session_start();
ini_set('error_reporting', 'E_ALL ^ E_NOTICE');
header("Content-type: text/html; charset=utf-8");
include("conn.php");
$foodID = $_GET['id'];
$arr = mysql_query("select * from foodmenu where foodID=$foodID");
$result = mysql_fetch_array($arr);
?>
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Tumy</title>
<link rel="stylesheet" href="css/foodcart.css">
</head>
<body>
<div class="headerwrapper">
<div id="header" class="container">
<div class="logo"> <a href="homepage.php"><img src="image/LOGO.png" alt="logo" width="165" height="74"></a> </div>
<nav>
<ul id="navigations">
<li><a href="homepage.php">HOME</a></li>
<li> <a href="restaurant.php">RESTAURANT</a></li>
<li><a href="rating.php">CUSTOMER FEEDBACK</a></li>
<li><a href="userprofile.php">USER PROFILE</a></li>
<li><a href="logout.php">LOGOUT</a></li>
</ul>
<a href="order.php"><img src="image/cart.png" width="50" height="50"></a>
</nav>
</div>
</div>
<div class="indexbox">
<?php
$result = mysql_query("SELECT * FROM foodmenu where foodID = '$foodID'");
while($row=mysql_fetch_array($result)){
?>
<div class="detailback">
<a href="restaurant.php">Restaurant</a><span>></span><?php echo $row["restaurant_name"];?><span>></span>
<button onClick="goBack()" style="background-color:#F00; border:solid;">Food Menu</button>
<script> function goBack(){
window.history.back();
}</script>
</div>
<div class="detail">
<div class="detailtop">
<dl>
<input type="hidden" name="id" value="<?php echo $row["foodID"];?>" />
<dt>
<img src="<?php echo $row["food_img"];?>" />
<input name="img" type="hidden" class="img" value="<?php echo $row["food_img"];?>" /> </dt>
<dd>
<form action="order.php" method="get" name="send" onSubmit="return Check()" enctype="multipart/form-data">
<h3><?php echo $row["food_name"];?>
<input name="name" type="hidden" class="name" value="<?php echo $row["food_name"];?>" /></h3>
<div class="detailtips">
<?php echo $row["food_description"];?>
</div>
<p><span>Restaurant:</span><strong><?php echo $row["restaurant_name"];?>
<input name="restaurant" type="hidden" class="restaurant" value="<?php echo $row["restaurant_name"];?>" />
</strong></p>
<p><span>Type :</span><strong><?php echo $row["food_type"];?></strong></p>
<input name="num" type="hidden" class="num" value="<?php echo $row["order_num"];?>" />
<p><span>Price :</span>RM <strong><?php echo $row["food_price"];?>
<input name="price" type="hidden" class="price" value="<?php echo $row["food_price"];?>" /></strong></p>
<div class="order" style=" padding-top:20px; padding-left:20px;">
<input name="" type="submit" value="" class="ordersubmit" style=" margin-left:30px; margin-top:20px;">
</div>
</form>
</dd>
</dl>
<?php }?>
</div>
</div>
</div>
<div class="copyrightswrapper">
<div id="copyrights" class="container">
<p>© TUMY - All Rights Reserved.</p>
</div>
</div>
</body>
</html>