This is where you share YOUR scripts with others
Moderators: macek, egami, gesf
by Raja89 » Tue Oct 18, 2011 1:18 am
i am facing trouble with retrieving session variables data as i want to insert these data into my database.
- Code: Select all
<?php
function checkout()
{
$datetime = date_create();
$datetime = date_timestamp_get($datetime);
$total_amount = $_SESSION['total_price'];
$user = $_SESSION['my_username'];
$pass = $_SESSION['my_password'];
$sql="SElECT id FROM customer where customer.username='$user' AND customer.password='$pass'";
$customser_id = mysql_query($sql);
$sql2 = "INSERT INTO order_header (customer_id) VALUES ( '$customser_id ')";
$result2 = mysql_query($sql2);
$_SESSION['my_order'] = $result2['id'];
print_r ($_SESSION['cart']);
foreach ($_SESSION['cart'] as $id => $quantity):
$product = get_product($id);
$product_id = $product['id'];
$product_quantity = $quantity;
$sub_total = $product['unit_price'] * $product_quantity;
echo "<br>".$product_id."-".$product_quantity."-".$sub_total;
echo"</br>";
$sql3 = "INSERT INTO order_details ('product_id', 'product_quantity', 'sub_total', 'order_id')
VALUES ('".$product['id']."', '".$quantity."', '".$product['unit_price'] * $product_quantity."', '1')";
mysql_query($sql3);
endforeach;
}
?>
I am able to print the $_SESSION['username'], $_SESSION['password'] and $_SESSION['cart'].
However the sql query does not return any values. any help would be kindly appreciated as i am still a newbie to php.
-
Raja89
- New php-forum User

-
- Posts: 3
- Joined: Tue Oct 18, 2011 1:07 am
by lokanath7 » Tue Oct 18, 2011 2:21 am
change this line
$sql2 = "INSERT INTO order_header (customer_id) VALUES ( '$customser_id ')";
to
$sql2 = "INSERT INTO order_header (customer_id) VALUES ( '$customser_id')";
if still have issues then give the full supporting code.
-
lokanath7
- New php-forum User

-
- Posts: 139
- Joined: Mon Nov 15, 2010 12:11 am
by Raja89 » Tue Oct 18, 2011 7:37 am
with much respect & appreciation there's nothing change in what u suggested.

-
Raja89
- New php-forum User

-
- Posts: 3
- Joined: Tue Oct 18, 2011 1:07 am
by lokanath7 » Wed Oct 19, 2011 2:10 am
mark the last part of the query as there is an extra space in the code and i told u to delete that space...
inly this much change i hv suggested u.
-
lokanath7
- New php-forum User

-
- Posts: 139
- Joined: Mon Nov 15, 2010 12:11 am
by Raja89 » Thu Oct 20, 2011 11:05 am
Thank u so much for ur help.
I been able to solve the problem on my own.

-
Raja89
- New php-forum User

-
- Posts: 3
- Joined: Tue Oct 18, 2011 1:07 am
by mikeyarde » Tue Nov 22, 2011 6:48 am
It is more important that to update the stock so you can see which product is your current product and sale more also you can know the market of your product. it is also useful to maintain the sales and profit and loss account.
-
mikeyarde
- New php-forum User

-
- Posts: 2
- Joined: Tue Nov 22, 2011 6:36 am
Return to Your Scripts
Who is online
Users browsing this forum: No registered users and 1 guest