ショッピング カートの詳細を mysql データベースに挿入したいのですが、mysql データベースに空白のフィールドが表示されます
ここに私のページコード
<?php
include('config.php');
$id=$_REQUEST['id'];
include("cart/db.php");
include("cart/functions.php");
if($_REQUEST['command']=='delete' && $_REQUEST['id']>0){
remove_product($_REQUEST['id']);
}
else if($_REQUEST['command']=='clear'){
unset($_SESSION['cart']);
}
else if($_REQUEST['command']=='update'){
$max=count($_SESSION['cart']);
for($i=0;$i<$max;$i++){
$id=$_SESSION['cart'][$i]['id'];
$q=intval($_REQUEST['product'.$id]);
if($q>0 && $q<=999){
$_SESSION['cart'][$i]['qty']=$q;
}
else{
$msg='Some proudcts not updated!, quantity must be a number between 1 and 999';
}
}
}
if(isset($_REQUEST['order']))
{
$product=$_POST['product'];
$queryproduct=mysql_query("INSERT INTO shoppingcart VALUES ('','','','$product','','','','')") or die("Order Query Problem");
}
?>
Mysqlデータベーステーブルに挿入したいショッピングカートテーブル
<form name="form1" method="post">
<input type="hidden" name="id" />
<input type="hidden" name="command" />
<div class="main_content">
<div align="center">
<table style="background-color:#F0F0F0; border:solid 1px; width:800px;">
<?php
if(is_array($_SESSION['cart'])){
echo '<tr bgcolor="#FFFFFF" style="font-weight:bold"><td align="center"><font style="font-family:Arial,Helvetica,sans-serif; font-size:14px; color:#000;">Product Name</font></td><td align="center"><font style="font-family:Arial,Helvetica,sans-serif; font-size:14px; color:#000;">Product Image</font></td><td><font style="font-family:Arial,Helvetica,sans-serif; font-size:14px; color:#000;">Price</font></td><td><font style="font-family:Arial,Helvetica,sans-serif; font-size:14px; color:#000;">Qty</font></td><td><font style="font-family:Arial,Helvetica,sans-serif; font-size:14px; color:#000;">Amount</font></td><td><font style="font-family:Arial,Helvetica,sans-serif; font-size:14px; color:#000;">Options</font></td></tr>';
$max=count($_SESSION['cart']);
for($i=0;$i<$max;$i++){
$id=$_SESSION['cart'][$i]['id'];
$q=$_SESSION['cart'][$i]['qty'];
$product=get_product_name($id);
$image=get_product_image($id);
if($q==0) continue;
?>
<tr bgcolor="#FFFFFF"><td align="center"><font style="font-family:Arial,Helvetica,sans-serif; font-size:15px; color:#000;"><?php echo $product?></font></td><td align="center"><img src="admin/uploads/small0_<?php echo $image?>" width="150" height="150"></td>
<td><font style="font-family:Arial,Helvetica,sans-serif; font-size:15px; color:#000;">Rs.<?php echo get_price($id)?></font></td>
<td><input type="text" name="product<?php echo $id?>" value="<?php echo $q?>" maxlength="3" size="2" /></td>
<td><font style="font-family:Arial,Helvetica,sans-serif; font-size:15px; color:#000;">Rs.<?php echo get_price($id)*$q?></font></td>
<td><font style="font-family:Arial,Helvetica,sans-serif; font-size:15px; color:#000;"><a href="javascript:del(<?php echo $id?>)"><input type="button" class="button5" value="Remove" /></a></font></td></tr>
<?php
}
?>
<tr><td colspan="6" align="right"><b><font style="font-family:Arial,Helvetica,sans-serif; font-size:15px; color:#000;">Order Total: Rs.<?php echo get_order_total()?></font></b></td></tr>
<tr><td colspan="6" align="right"><font style="font-family:Arial,Helvetica,sans-serif; font-size:14px; color:#000; !important">Cash On Delivery & Free Shipping</font></td></tr>
<tr><td colspan="6" align="right"><?php $query1=mysql_query("SELECT * FROM category ORDER BY id ") or die ('Product Query Problem');
$row4=mysql_fetch_array($query1);$ids=$row4['id'];$cat_name=$row4['categories'];?><input type="button" class="button1" value="Continue Shopping" onclick="window.location='product.php'" /><input type="button" class="button2" value="Clear Cart" onclick="clear_cart()"><input type="button" class="button3" value="Update Cart" onclick="update_cart()"><input type="button" class="button4" name="order" id="order" value="Place Order" onclick="window.location='login.php'"></td></tr>
<?php
}
else{
echo "<tr bgColor='#FFFFFF'><td><font style='font-family:Arial,Helvetica,sans-serif; font-size:15px; color:#000;'>There are no items in your shopping cart!</font></td>";
}
?>
</table>
このページのデータベースから製品 ID とすべてを取得する
<?php
$id=$_REQUEST['id'];
function get_product_name($id){
$result=mysql_query("select * from products where id='$id'") or die("select name from products where serial=$pid"."<br/><br/>".mysql_error());
$row=mysql_fetch_array($result);
return $row['product'];
}
function get_product_image($id){
$result=mysql_query("select * from products where id='$id'") or die("select name from products where serial=$pid"."<br/><br/>".mysql_error());
$row=mysql_fetch_array($result);
return $row['image'];
}
function get_price($id){
$result=mysql_query("select * from products where id='$id'") or die("select name from products where serial=$pid"."<br/><br/>".mysql_error());
$row=mysql_fetch_array($result);
return $row['price'];
}
function remove_product($id){
$id=intval($id);
$max=count($_SESSION['cart']);
for($i=0;$i<$max;$i++){
if($id==$_SESSION['cart'][$i]['id']){
unset($_SESSION['cart'][$i]);
break;
}
}
$_SESSION['cart']=array_values($_SESSION['cart']);
}
function get_order_total(){
$max=count($_SESSION['cart']);
$sum=0;
for($i=0;$i<$max;$i++){
$id=$_SESSION['cart'][$i]['id'];
$q=$_SESSION['cart'][$i]['qty'];
$price=get_price($id);
$sum+=$price*$q;
}
return $sum;
}
function addtocart($id,$q){
if($id<1 or $q<1) return;
if(is_array($_SESSION['cart'])){
if(product_exists($id)) return;
$max=count($_SESSION['cart']);
$_SESSION['cart'][$max]['id']=$id;
$_SESSION['cart'][$max]['qty']=$q;
}
else{
$_SESSION['cart']=array();
$_SESSION['cart'][0]['id']=$id;
$_SESSION['cart'][0]['qty']=$q;
}
}
function product_exists($id){
$id=intval($id);
$max=count($_SESSION['cart']);
$flag=0;
for($i=0;$i<$max;$i++){
if($id==$_SESSION['cart'][$i]['id']){
$flag=1;
break;
}
}
return $flag;
}
?>