How To Used Order_id As Invoice Number And Converting Any Variable As Gloabal
I tried multiple times but have been stucked for long time, kindly mention that which method is better S_SESSION or GET Method to used some variable as global. And how to $date =
Solution 1:
To use $_SESSION
, you have to run session_start();
before your php code starts:
<?php
session_start();
if(isset($_POST['order']))
{
$user_id = $_SESSION['id'];
$date = date('Y-m-d H:i:s');
$username = $_SESSION['username'];
mysql_query("INSERT INTO tborder(user_id,`date`,username) VALUES('$user_id','$date','$username')") or die(mysql_error());
$i = mysql_insert_id();
if($i >0)
for($l=0;$l<count($_POST['product_id']);$l++)
{
$product_id = $_POST['product_id'][$l];
$quantity = $_POST['quantity'][$l];
$price = $_POST['price'][$l];
$discount = $_POST['discount'][$l];
$amount = $_POST['amount'][$l];
$username = $_SESSION['username'];
$user_id = $_SESSION['id'];
if(!isset($_SESSION['product_cart']))
$_SESSION['product_cart'] = [];
if(!isset($_SESSION['product_cart']['products']))
$_SESSION['product_cart']['products'] = [];
// save product to cart products array in $_SESSION
$_SESSION['product_cart']['products'][] = [
'id' => $product_id;
'quantity' => $quantity;
'price' => $price;
'discount' => $discount;
'amount' => $amount;
'username' => $username;
'user_id' => $user_id;
];
// I don't get what is this query for
mysql_query("INSERT INTO tborderdetail(order_id,product_id,quantity,price,discount,amount,username,user_id) VALUES('$i','$product_id','$quantity','$price','$discount','$amount','$username','$user_id')")or die(mysql_error());
}
// redirect after loop ends,
// unless it'll process only first array element
header('location:order.php');
}
// Do not include html templates before you not sure you'll stay on this page
include('header.php');
Post a Comment for "How To Used Order_id As Invoice Number And Converting Any Variable As Gloabal"