hi i am working in a project it is about online ordering of food ..
I have problem in createing the cart.
I have these tables
Member-will have the username and password, member id.
Fooddetails- will have foodid,foodname,fooddescrtion,foodimage,price.
Cartdetails-cart id ,quantity ,price,total,member id,
Orderdetails-order id,total,member id.
cart details has the ordered food details and the total.
orderdetails just has the total and order id .
my problem is the admin should know what are the foods ordered by the users
and the cartdetails should be destroyed as soon the user makes the order ..

Member Avatar for diafol

So what do you want? Unless you provide your code and show what's not working, I don't know how we can help.

<?php
session_start();
 require_once('connection/config.php');

    //Connect to mysql server
    $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
    if(!$link) {
        die('Failed to connect to server: ' . mysql_error());
    }

    //Select database
    $db = mysql_select_db(DB_DATABASE);
    if(!$db) {
        die("Unable to select database");
    }


$memid=$_POST['id'];
$qty=$_POST['quantity'];
$name=$_POST['name'];
$transcode=$_POST['transcode'];
$id=$_POST['butadd'];
//$ids=$_POST['ids'];

            $pprice = (int)$_REQUEST['price'];
            $pn = $_REQUEST['name'];
  $total= $pprice * $qty;

mysql_query("INSERT INTO cart_items (food_id, quantity, price, total, name, transactioncode) VALUES('$memid', '$qty', '$pprice', '$total', '$pn', '$transcode')");

header("location: order.php");

?>

This is the code which save the cart details ..cart will have the users select food items

`Inline Code Example Here`<?php 
 require_once('auth.php');
 require_once('connection/config.php');

    //Connect to mysql server
    $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
    if(!$link) {
        die('Failed to connect to server: ' . mysql_error());
    }

    //Select database
    $db = mysql_select_db(DB_DATABASE);
    if(!$db) {
        die("Unable to select database");
    }
?>
<form method ="post" action ="">
<?php

$name=$_POST['name'];
$quantity=$_POST['quantity'];
$price=$_POST['price'];
$total=$_POST['total'];
$transactioncode=$_POST['transactioncode'];

?>
<input name="transactioncode" type="hidden" value="<?php echo $transactioncode;?>" />
<input name="total" type="hidden" value="<?php echo $total;?>" />

<input name="name" type="hidden" value="<?php echo $name;?>" />
<input name="quantity" type="hidden" value="<?php echo $quantity;?>" />
<input name="price" type="hidden" value="<?php echo $price;?>" /></form>
<?php
$name=$_POST['name'];
$quantity=$_POST['quantity'];
$price=$_POST['price'];
$total=$_POST['total'];
$trasactiondate=date("d/m/Y");
$transactioncode=$_POST['transactioncode']; 

$regnum = $_POST['regnum'];

$data = mysql_query("SELECT * FROM  members where member_id=$transactioncode") or die(mysql_error());  
 while($info = mysql_fetch_array( $data )) {
 $reg = $info['regnum'];
} 
if($regnum != $reg){
echo "wrong regnum Num";
exit(0);
}



mysql_query("INSERT INTO orders (gtotal, transactiondate, transactioncode,bill_id) VALUES('$total','$trasactiondate', '$transactioncode','$regnum')");


?>
<div> 
<a  href="foodorders.php"><img src="images/dine1.png" width="100%" height="80%" />click here view your order </a>
Thank you ! your order has been placed succesfully ... .</div>

this is the code that saves the total and member id in order table

USer can add favorite food in cart for ordereing .
The problem is since i use cart as a table and the cart has the food items even after the food is orders as soon the user order the food it shoul not be available in the cart for the user .due to this im facing duplication ..

and the order table has only the details of the member and the total ..
the food items is unavailable to view by the admin since the admin should know the food items for further process

Cart table should has food's ID in case the user order the food and delete from cart table where food's ID and user's ID found.

Ya name will will be saved ..Bt tatas not the problem ..what I'm facing isthat even after the food is ordered it ifound in the cart table I want to delete it after the foods are ordered .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.