469,315 Members | 1,539 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,315 developers. It's quick & easy.

Shopping cart for multiple tables

basicaly i am creating a shopping cart for my website however creating a shopping cart for one table of items is easy but can someone direct me on how to create a shopping cart that can handle more than one table of items. i really need ur help on this

thanks

ashraf
Apr 10 '08 #1
11 2054
to elaborate further on my problem i am trying to execute the code below there are two seperate item tables. 1, shirts 2, trousers and i am trying to integrate it so that when customers select the item it would appear on the shopping basket even though there arein seperate tables. hope this makes sense.

Code:

[PHP]<?php
session_start();

$conn = mysql_connect("localhost", "root", "")
or die (mysql_error());
mysql_select_db ("noble", $conn) or die (mysql_error());

if ($_POST[Bas_Item_ID] != "") {
$shirt_info = "SELECT Shirt_Brand
FROM Shirts
WHERE Shirt_ID =$_POST[Bas_Item_ID]";
$shirt_info_res = mysql_query ($shirt_info) or die (mysql_error());

if (mysql_num_rows ($shirt_info_res) < 1) {
header ("Location: Display_Smart.php");
exit;
} else {
$trouser_info = "SELECT Trouser_Brand
FROM Trousers
WHERE Trouser_ID =$_POST[Bas_Item_ID]";
$trouser_info_res = mysql_query ($trouser_info) or die (mysql_error());

if (mysql_num_rows ($trouser_info_res) < 1) {
header ("Location: Display_Smart.php");
exit;
} else {
$trouser_brand = mysql_result($trouser_info_res,0,'Trouser_Brand');
$shirt_brand = mysql_result($shirt_info_res,0,'Shirt_Brand');
}
$addcart = "INSERT INTO Basket
VALUES ('','$[COOKIE]PHPSESSID', '$_POST[Bas_Item_ID]', '$_POST[Bas_Item_Qty]', '$_POST[Bas_Item_Size]',
now())";

mysql_query($addcart);

header("location: Showcart.php");
exit;

}

} else {
header ("Location: Display_Smart.php");
exit;
}

?>[/PHP]

thanks in advance
Apr 10 '08 #2
ive updated the code so that the shirts can go through to the basket but when i try putting the trousers through the basket nothng happens. please please please help it's urgent.

ashraf

updated code[php]
<?php
session_start();
$conn = mysql_connect("localhost", "root", "")
or die (mysql_error());
mysql_select_db ("noble", $conn) or die (mysql_error());
if ($_POST[Bas_Item_ID] != "") {
$shirt_info = "SELECT Shirt_Brand
FROM Shirts
WHERE Shirt_ID =$_POST[Bas_Item_ID]";
$shirt_info_res = mysql_query ($shirt_info) or die (mysql_error());

if (mysql_num_rows ($shirt_info_res) < 1) {
header ("Location: Display_Smart.php");
exit;
} else {
$shirt_brand = mysql_result($shirt_info_res,0,'Shirt_Brand');
$addcart = "INSERT INTO Basket
VALUES ('','$[COOKIE]PHPSESSID', '$_POST[Bas_Item_ID]', '$_POST[Bas_Item_Qty]', '$_POST[Bas_Item_Size]',
now())";
mysql_query($addcart);
header("location: Showcart.php");
exit;
}
if ($_POST[Bas_Item_ID] != "") {
$trouser_info = "SELECT Trouser_Brand
FROM Trousers
WHERE Trouser_ID = $_POST[Bas_Item_ID]";
$trouser_info_res = mysql_query ($trouser_info) or die (mysql_error());
if (mysql_num_rows ($trouser_info_res) < 1) {
header ("Location: Display_Smart.php");
exit;
} else {
$trouser_brand = mysql_result($trouser_info_res,0,'Trouser_Brand');

$addcart = "INSERT INTO Basket
VALUES ('','$[COOKIE]PHPSESSID', '$_POST[Bas_Item_ID]', '$_POST[Bas_Item_Qty]', '$_POST[Bas_Item_Size]',
now())";
mysql_query($addcart);
header("location: Showcart.php");
exit;
}
} else {
header ("Location: Display_Smart.php");
exit;
}
}
?>[/php]
Apr 10 '08 #3
ronverdonk
4,258 Expert 4TB
As a full member now, you should know that we expect your code to be posted in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use the tags in future.

MODERATOR.
Apr 10 '08 #4
i apologise it was a mistake. any chance u could help me with my code though i am gettin really frustrated and dont know wat to do.
Apr 10 '08 #5
TheServant
1,168 Expert 1GB
I am not following what the problem is... Also, I am confused why you only have one POST variable (Bas_Item_ID). Both if statements are the same:
6. if ($_POST[Bas_Item_ID] != "") {
24. if ($_POST[Bas_Item_ID] != "") {

What error are you getting? What exactly is coming up, or not coming up?
Apr 10 '08 #6
for the the shirt table i can go through to the checkout basket but for the trousers table it comes up with a blank screen and i want both items to be added to the cart but only one table allows it. is there anyway i can add extra code to allow trousers to go through to the cart.
Apr 11 '08 #7
code green
1,726 Expert 1GB
You have a blank screen because you have no error checking or echo statements.
I have looked at the code and it is quite obvious what is happening -
If you don't buy a shirt the script exits.
As TheServant pointed out, one POST variable is used for both shirts and trousers.
Now please put some error checking and echo statements in your code
Apr 11 '08 #8
thanks for the response i have updated the code which looks like this :

[PHP]
<?php

session_start();

$conn = mysql_connect("localhost", "root", "")

or die (mysql_error());

mysql_select_db ("noble", $conn) or die (mysql_error());

if ($_POST[Bas_Item_ID] != "") {

$shirt_info = "SELECT Shirt_Brand

FROM Shirts

WHERE Shirt_ID =$_POST[Bas_Item_ID]";

$shirt_info_res = mysql_query ($shirt_info) or die (mysql_error());
if (mysql_num_rows ($shirt_info_res) < 1) {
die (mysql_error());
exit;
} else {
$shirt_brand = mysql_result($shirt_info_res,0,'Shirt_Brand');
}
$trouser_info = "SELECT Trouser_Brand
FROM Trousers
WHERE Trouser_ID = $_POST[Bas_Item_ID]";
$trouser_info_res = mysql_query ($trouser_info) or die (mysql_error());
if (mysql_num_rows ($trouser_info_res) < 1) {
die (mysql_error());
exit;
} else {
$trouser_brand = mysql_result($trouser_info_res,0,'Trouser_Brand');

$addcart = "INSERT INTO Basket
VALUES ('','$[COOKIE]PHPSESSID', '$_POST[Bas_Item_ID]', '$_POST[Bas_Item_Qty]', '$_POST[Bas_Item_Size]',
now())";
mysql_query($addcart);
header("location: Showcart.php");
exit;
}
} else {
header ("Location: Display_Smart.php");
exit;
}
?>[/PHP]

the error i get is :

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\wamp\www\addtocart.php:2) in C:\wamp\www\addtocart.php on line 4

Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\addtocart.php:2) in C:\wamp\www\addtocart.php on line 45
Apr 11 '08 #9
code green
1,726 Expert 1GB
This means you are trying to send header information to the browser
when output has already been sent or header information has already been sent.
Apr 11 '08 #10
how can i sort this problem out
Apr 11 '08 #11
code green
1,726 Expert 1GB
how can i sort this problem out
Well, all the information is in the error message.
On which line the problem occurred and in which file.
You cannot send multiple header information to a browser
Apr 11 '08 #12

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by madison | last post: by
1 post views Thread by Paul Goodley | last post: by
2 posts views Thread by JJ | last post: by
1 post views Thread by jecha | last post: by
reply views Thread by jasone | last post: by
3 posts views Thread by Paulo | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.