Jump to content

shopping cart


DeadDude

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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);
?>

Link to comment
Share on other sites

<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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.