DeadDude Posted May 19, 2007 Share Posted May 19, 2007 I have an assignment for college to create a website, but i need a working shopping cart for it. Up to now i have managed to create the buy script and allow it to input the item id into the basket but i'm slightly stuck on how to get it to post the item name in the basket as well. any help would be appreciated cheers James Quote Link to comment https://forums.phpfreaks.com/topic/52106-shopping-cart/ Share on other sites More sharing options...
MadTechie Posted May 19, 2007 Share Posted May 19, 2007 how are you storeing the cart data ? Cookies session database etc ? can you post what you have so far.. if you are using a database just lookup the item id in the database and pull the name Quote Link to comment https://forums.phpfreaks.com/topic/52106-shopping-cart/#findComment-256898 Share on other sites More sharing options...
DeadDude Posted May 19, 2007 Author Share Posted May 19, 2007 i have the item id, and the basket id etc saved in the database, at the moment i haven't worked out how to get it to post the item name in the database too so it will displayed in the basket i'm actually only just started with php cause of this assignment lol Quote Link to comment https://forums.phpfreaks.com/topic/52106-shopping-cart/#findComment-256899 Share on other sites More sharing options...
MadTechie Posted May 19, 2007 Share Posted May 19, 2007 your need to show some code as how to get it to post the item name in the database too so it will displayed in the basket doesn't make much sense if yo have don't it with the id then its the same thing! Quote Link to comment https://forums.phpfreaks.com/topic/52106-shopping-cart/#findComment-256901 Share on other sites More sharing options...
DeadDude Posted May 19, 2007 Author Share Posted May 19, 2007 this is the code that i'm using for shopping_basket.inc.php <?php $id=$_POST['id']; $db=mysql_connect("localhost","basket","PASSWORD"); mysql_select_db("college",$db); $query="INSERT INTO basket (item_id, basket_id) values (".$id.", 2)"; mysql_query($query, $db); ?> This is the code that i currently have for the basket.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <table width="200" border="1"> <tr> <td> </td> <td>Item ID </td> <td>Number of Items </td> </tr> <?php $id=$_GET['id']; $db=mysql_connect("localhost","basket","PASSWORD"); mysql_select_db("college",$db); $query="SELECT * FROM basket WHERE basket_id=" . $id; $result=mysql_query($query, $db); while($row=mysql_fetch_row($result)) { ?> <tr> <td><?php echo $row[0]; ?></td> <td><?php echo $row[1]; ?></td> <td><?php echo $row[2]; ?></td> </tr> <?php } ?> </table> </body> </html> This is the code thats been used for the buy buttons next to the actual items <table width="550" border="0" align="center"><tr><td width="118"><table width="550" border="0" align="center"> <tr> <td width="94"><img src="Images/action1.jpg" width="90" height="151" /></td> <td width="446"><p>DEJAVU</p> <form id="form1" name="form1" method="post" action=""> <label> <input type="submit" name="Submit" value="Buy" /> <input name="id" type="hidden" id="id" value="1" /> </label> </form> <p> </p></td> </tr> thats the code for the buy button along with the item name and image next to it Quote Link to comment https://forums.phpfreaks.com/topic/52106-shopping-cart/#findComment-256909 Share on other sites More sharing options...
MadTechie Posted May 19, 2007 Share Posted May 19, 2007 OK well this is the part i think you mean <?php $id=$_POST['id']; $db=mysql_connect("localhost","basket","PASSWORD"); mysql_select_db("college",$db); $query="INSERT INTO basket (item_id, basket_id) values (".$id.", 2)"; mysql_query($query, $db); ?> in the form <table width="550" border="0" align="center"><tr><td width="118"><table width="550" border="0" align="center"> <tr> <td width="94"><img src="Images/action1.jpg" width="90" height="151" /></td> <td width="446"><p>DEJAVU</p> <form id="form1" name="form1" method="post" action=""> <label> <input type="submit" name="Submit" value="Buy" /> <input name="Itemid" type="hidden" id="Itemid" value="1" /> <input name="Basketid" type="hidden" id="Basketid" value="2" /> </label> </form> <p> </p></td> </tr> and update <?php $Itemid=$_POST['Itemid']; $Basketid=$_POST['Basketid']; $db=mysql_connect("localhost","basket","PASSWORD"); mysql_select_db("college",$db); $query="INSERT INTO basket (item_id, basket_id) values ($Itemid, $Basketid)"; mysql_query($query, $db); ?> Quote Link to comment https://forums.phpfreaks.com/topic/52106-shopping-cart/#findComment-256912 Share on other sites More sharing options...
DeadDude Posted May 19, 2007 Author Share Posted May 19, 2007 the basket ID that my tutor set me up to use is a unique id for the item that is in the basket so that each item that hets added has a different ID Quote Link to comment https://forums.phpfreaks.com/topic/52106-shopping-cart/#findComment-256915 Share on other sites More sharing options...
MadTechie Posted May 19, 2007 Share Posted May 19, 2007 and how does that affect the changes i made ?!! Quote Link to comment https://forums.phpfreaks.com/topic/52106-shopping-cart/#findComment-256916 Share on other sites More sharing options...
DeadDude Posted May 19, 2007 Author Share Posted May 19, 2007 probably doesn't lol i'm new to php so it confuses me slightly Quote Link to comment https://forums.phpfreaks.com/topic/52106-shopping-cart/#findComment-256926 Share on other sites More sharing options...
MadTechie Posted May 19, 2007 Share Posted May 19, 2007 the reason i changed $id=$_POST['id']; is because were dealing with 2 items and $BasketID is easier to remember than just say $id2 Quote Link to comment https://forums.phpfreaks.com/topic/52106-shopping-cart/#findComment-256929 Share on other sites More sharing options...
DeadDude Posted May 19, 2007 Author Share Posted May 19, 2007 how would that would that work for posting the name of the item into the tabel as well though? Quote Link to comment https://forums.phpfreaks.com/topic/52106-shopping-cart/#findComment-256937 Share on other sites More sharing options...
MadTechie Posted May 19, 2007 Share Posted May 19, 2007 i won't post the name in their but just the id, i assume the items are also in the database! Quote Link to comment https://forums.phpfreaks.com/topic/52106-shopping-cart/#findComment-256943 Share on other sites More sharing options...
DeadDude Posted May 19, 2007 Author Share Posted May 19, 2007 nope, the items were all in html format until i had to chance the files to php so nothings in the database at the moment, apart from what is dumped there when the buy button is selected Quote Link to comment https://forums.phpfreaks.com/topic/52106-shopping-cart/#findComment-256944 Share on other sites More sharing options...
MadTechie Posted May 19, 2007 Share Posted May 19, 2007 Problem is i see no items in the code supplied! Quote Link to comment https://forums.phpfreaks.com/topic/52106-shopping-cart/#findComment-256952 Share on other sites More sharing options...
DeadDude Posted May 19, 2007 Author Share Posted May 19, 2007 <table width="550" border="0" align="center"><tr><td width="118"><table width="550" border="0" align="center"> <tr> <td width="94"><img src="Images/action1.jpg" width="90" height="151" /></td> <td width="446"><p>DEJAVU</p> <form id="form1" name="form1" method="post" action=""> <label> <input type="submit" name="Submit" value="Buy" /> <input name="Itemid" type="hidden" id="Itemid" value="1" /> <input name="Basketid" type="hidden" id="Basketid" value="2" /> </label> </form> <p> </p></td> </tr> one of the items is DEJAVU which is the one that i'm trying to get sorted as i only need to evidence that the shopping cart works for now, so i'm wanting it to dump the item id and the name over mainly and the price later on Quote Link to comment https://forums.phpfreaks.com/topic/52106-shopping-cart/#findComment-256956 Share on other sites More sharing options...
MadTechie Posted May 19, 2007 Share Posted May 19, 2007 this is a bad route but ok... but you just need to use the exact same idea as before in the shopping_basket.inc.php Quote Link to comment https://forums.phpfreaks.com/topic/52106-shopping-cart/#findComment-256957 Share on other sites More sharing options...
DeadDude Posted May 19, 2007 Author Share Posted May 19, 2007 what you mean? Quote Link to comment https://forums.phpfreaks.com/topic/52106-shopping-cart/#findComment-256959 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.