hi.
my names StegS.
im tryin 2 get a shopping cart i wrote in php4 2 work properly but it doesnt.
i'll give a quick rundown.
3 mysql tables...
products with all products (divided into cellphones, hifi & tv)
wishlist 2 hold items which 2 wish 2 purchase lata
basket wich is the actual basket.
I basically need 2 be able 2 click on the 'add 2 wish list button' or the 'add 2 basket button' & then it adds that specific record into the wishlist / basket table.
at the moment it just adds the same record where the id = $count which is '4' for test purposes.
I think the only way is to link some sort of index number from the button to the actual record on the page.
ie... when you click 'add 2 wishlist' button next to the nokia 3210... it must add the nokia 3210 & relevant details into the wishlist table.
iv added a button as part of the wishlist table in a column called add2w, & when clicked it goes to the wishlist page & adds the test record where id = $count (which is '4'), but thats not all wat i need it 2 do obviously.
please help any1. id really like 2 get this goin.. heres the code for reference below... thanx
shweeet..
StegS
<?php
global $name;
global $code;
$dbcon = mysql_connect("localhost" , "gdando");
if (! @mysql_connect)
{
print "error connecting 2 db server";
}
if (! @mysql_select_db("shopping"))
{
print "error connecting to shopping database" ;
}
echo("
<html>
<body bgcolor=\"#ccFF0F\">
<table width=\"70%\">
<tr ><font face=\"ambient\" size=\"6\">WELCOME 2 STEGS SHOP<BR> WHERE U GET LESS 4 MORE 🙂</font>
</tr>
<tr bgcolor=\"white\">
chooz your category below<br>
</tr>
<tr>
<form action=\"$PHP_SELF?\" method=\"GET\">
<input type=\"submit\" name=\"cat\" value=\"cellphones\">
<BR><br>
<input type=\"submit\" name=\"cat\" value=\"hifi\">
<BR><br>
<input type=\"submit\" name=\"cat\" value=\"television\">
</tr>
<tr bgcolor=\"YELLOW\"><br>
Or search for a specific product
<input type=\"text\" name=\"name\">
<input type=\"submit\" name=\"search\" value=\"search\">
</tr>
");
foreach ( $HTTP_GET_VARS as $key => $value )
{
if ($key == "cat")
{
$count=0;
$cat = $value;
$select = @mysql_query("select * from products where category = '$cat' ");
while ($row = mysql_fetch_array($select))
{
$count++;
$id = $row["id"];
$code = $row["code"];
$name = $row["name"];
$old_price = $row["old_price"];
$discount = $row["discount"];
$price = $row["price"];
$add2w = $row["add2w"];
print "<table border=\"2\" bordercolor=\"BLUE\"><tr><td>code : " . $code . "</td></tr>";
print "<tr><td>name : " . $name . "</td></tr>";
print "<tr><td>old price : R" . $old_price . "</td></tr>";
print "<tr><td>discount : R" . $discount . "</td></tr>";
print "<tr><td>TODAYS price : R" . $price . "</td></tr>";
print "<tr><td>" . $add2w . "</td></tr>";
print" <tr><td>QTY
<input type=\"text\" name=\"qty\" value=\"\">
<input type=\"submit\" name=\"add\" value=\"Addtobasket\">
<input bgcolor =\"RED\" type=\"submit\" name=\"wish\" value=\"Addtowishlist\">
</td></tr></table>";
}
}
if ($key == "name")
{
$count=0;
$name = $value;
$select = @("select id, code, name, old_price, discount, price from products where name = '$name' ");
while ($row = mysql_fetch_array($select))
{
$count++;
$id = $row["id"];
$code = $row["code"];
$name = $row["name"];
$old_price = $row["old_price"];
$discount = $row["discount"];
$price = $row["price"];
print "<table border=\"2\"><tr><td>code : " . $code . "</td></tr>";
print "<tr><td>name : " . $name . "</td></tr>";
print "<tr><td>old price : R" . $old_price . "</td></tr>";
print "<tr><td>discount : R" . $discount . "</td></tr>";
print "<tr><td>TODAYS price : R" . $price . "</td></tr>";
print "<tr><td>QTY
<input type=\"text\" name=\"qty\" value=\"\">
<input type=\"submit\" name=\"add\" value=\"Addtobasket\">
<input bgcolor =\"RED\" type=\"submit\" name=\"wish\" value=\"Addtowishlist\">
</td></tr></table>";
}
}
if ($key == "qty")
{
$qty = $value;
print "qty = $qty<br>";
}
if ($key == "ndx")
{
$ndx = $value;
}
if ($key == "wish")
{
print "ndx = $ndx <br>";
print "count = $count<br>";
$count = 4;
print "count now = $count<br>";
$sel = @("select id, code, name, category, price from products where id = '$count'");
while ($row = mysql_fetch_array($sel))
{
$id = $row["id"];
$code = $row["code"];
$name = $row["name"];
$category = $row["category"];
$price = $row["price"];
}
$name1 = $value;
// print "qty=$qty<br><br><br><BR> ";
// for ($i=1;$i<=$qty;$i++)
// {
// print "qty=$qty";
$insert = mysql_query("insert into wishlist (code, name, category, price) values ('$code', '$name', '$category', '$price')");
// }
$select = @("select * from wishlist");
print "<a href=\"search.php4\">Return back to shop</a>";
print "<br><br>Your WISH LIST now contains the following items<br><br>";
while ($row = mysql_fetch_array($select))
{
$id = $row["id"];
$code = $row["code"];
$name = $row["name"];
$category = $row["category"];
$price = $row["price"];
$tot_w_price = $tot_w_price + $price;
print "<table border=\"2\" bordercolor=\"RED\"><tr><td>" . $row["id"] . " code : " . $row["code"] . "</td></tr>";
print "<tr><td>name : " . $row["name"] . "</td></tr>";
print "<tr><td>category : " . $row["category"] . "</td></tr>";
print "<tr><td>price : R" . $price . "</td></tr>";
}
print "<br><br>Your WISH LIST's total cost amounts to : R $tot_w_price";
// $select = @("select price from wishlist");
// while ($row = mysql_fetch_array($select))
// {
// $w_price = $row["price"];
// $tot_w_price = $tot_w_price + $w_price;
// }
}
if ($key == "add")
{
// $name1 = $value;
// print "key = $key -- value = $value <br> code = $code <br> name = $name <br> name1 = $name1 <br><br>";
// print "qty == $qty";
// for ($i=1;$i<=$qty;$i++)
// {
// print "qty ------ $qty";
$sel = @mysql_query("select id, code, name, category, price from products where id = 1");
while ($row = mysql_fetch_array($sel))
{
$id = $row["id"];
$code = $row["code"];
$name = $row["name"];
$category = $row["category"];
$price = $row["price"];
}
$insert = mysql_query("insert into basket (code, name, category, price) values ('$code', '$name', '$category', '$price')");
// }
if ($insert)
{
print "<BR>The following product(s) have recently been successfully added to your basket <br><br>";
print "Product Code : <b>$code</b> <br>";
print "Product Name : <b>$name</b> <br>";
$select = @mysql_query("select * from basket");
print "<br><br>Your Basket now contains the following items<br><br>";
while ($row = mysql_fetch_array($select))
{
$id = $row["id"];
$code = $row["code"];
$name = $row["name"];
$category = $row["category"];
$price = $row["price"];
$tot_b_price = $tot_b_price + $price;
print "<table border=\"2\" bordercolor=\"BLACK\"><tr><td>code : " . $row["code"] . "</td></tr>";
print "<tr><td>name : " . $row["name"] . "</td></tr>";
print "<tr><td>category : " . $row["category"] . "</td></tr>";
print "<tr><td>price : R" . $price . "</td></tr>";
}
// $select = @("select price from basket");
// while ($row = mysql_fetch_array($select))
// {
// $b_price = $row["price"];
// $tot_b_price = $tot_b_price + $b_price;
// }
print "<br><br>Your BASKET's total cost amounts to : R $tot_b_price";
}
else
{
print "<b>UNFORTUNATELY</b> the following product(s) could not be successfully added to your basket <br><br>";
print "Product Code : <b>$code</b> <br>";
print "Product Name : <b>$name</b> <br>";
}
print "<a href=\"search.php4\">Return back to shop</a>";
}
}
// print "<form action=\"$PHP_SELF?\" method=\"POST\"><input type=\"submit\" name=\"add\" value=\"Add to basket\">";
// $select = @("select id, code, name from products where name = '$name' ");
// while ($row = mysql_fetch_array($select))
// {
// $id = $row["id"];
// $code = $row["code"];
// $name = $row["name"];
// print "<table border=\"2\" bordercolor=\"BLUE\"><tr><td>code : " . $code . "</td></tr>";
// print "<tr><td>name : " . $name . "</td></tr>";
// print "<tr><td><form action=\"$PHP_SELF?\" method=\"POST\">
// <input type=\"text\" name=\"qty\" value=\"1\">
// <input type=\"submit\" name=\"add\" value=\"Add to basket\"></td></tr></table>";
// }
echo("</html>");
?>