php - Add-to-cart coding is that correct with form? -
<?php session_start(); include("conn.php"); $action = $_post['action']; $user = $_session['username']; if(empty($user)){ echo"<script>alert('please log in!');window.location='log in.php';</script>"; exit; } if($action == 'add'){ $cart_arr = array( 'foodid'=>$_post['foodid'], 'order_num'=>$_post['order_num'], 'food_type'=>$_post['food_type'], ); $cart_session = $_session['cart_'.$user]; if(empty($cart_session)){ $cart_session[$cart_arr['foodid']] = $cart_arr; } else if(!empty($cart_session[$cart_arr['foodid']])){ $cart_session[$cart_arr['foodid']]['order_num']+=$cart_arr['order_num']; } else { echo $cart_session[$cart_arr['foodid']] = $cart_arr; } $_session['cart_'.$user] = $cart_session; } else if($action == 'clear'){ $_session['cart_'.$user]=array(); echo"<script>alert('shopping cart empty, return home!');window.location='homepage.php';</script>"; exit; } else if($action == 'change'){ $temp_cart = $_session['cart_'.$user]; foreach($temp_cart $k=>$v){ if($_post['goods_'.$k]!= $v['order_num']){ $temp_cart[$k]['order_num'] = $_post['goods_'.$k]; } if($_post['goods_'.$k] == 0){ unset($temp_cart[$k]); } } $_session['cart_'.$user] = $temp_cart; } if(empty($_session['cart_'.$user])){ echo"<script>alert('shopping cart empty, please add orders!');window.location = 'homepage.php';</script>"; exit; } $goods_id = array(); $cart = $_session['cart_'.$user]; $v['food_type'] = $_post['food_type']; foreach($cart $k=>$v){ $goods_id[$v['foodid']] = $v['foodid']; } $goods_id_str = implode(",",$goods_id); mysql_query("set names utf8"); $sql = "select * foodmenu foodid in (".$goods_id_str.")"; $query = mysql_query($sql); $cart_goods = array(); while($arr = mysql_fetch_array($query)){ $cart_goods[$arr['foodid']] = $arr; } foreach($cart $k=>$v){ $cart[$k]['food_name'] = $cart_goods[$k]['food_name']; $cart[$k]['food_img'] = str_replace("../","",$cart_goods[$k]['food_img']); $cart[$k]['food_price'] = $cart_goods[$k]['food_price']; $cart[$k]['food_description'] = $_post['food_description']; } ?>
may know coding correct? because shows blank page when click on button on previous php add-to-cart purpose , shows normal header @ top. attach form access php.
<div class="detailtop"> <?php $result = mysql_query("select * foodmenu foodid = '$foodid'"); while($row=mysql_fetch_array($result)){ ?> <dl> <dt> <img src="<?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"];?></h3> <div class="detailtips"> <?php echo $row["food_description"];?> </div> <p><span>restaurant:</span><strong><?php echo $row["restaurant_name"];?></strong></p> <p><span>type :</span><strong><?php echo $row["food_type"];?></strong></p> <p><span>price :</span>rm <strong><?php echo $row["food_price"];?><input name="num" type="hidden" class="num" value="<?php echo $row["food_price"];?>" /></strong></p> <div class="order" style=" padding-top:20px; padding-left:20px;"> <input name="id" type="hidden" value="<?php echo $row["foodid"];?>" /> <input name="" type="submit" value="" class="ordersubmit" style=" margin-left:30px; margin-top:20px;"> </div> </form> </dd> </dl> <?php }?> </div>
Comments
Post a Comment