Jump to content

HELP creating a shopping basket with php, Mysql and HTML


wazza

Recommended Posts

hay

 

I have im having trouble creating a shopping basket where i can add and remove items i have created a search and a add button however i am struggling to create the rest the code i have search's all the DVD's i have in store puts the information in table format and i have check boxes at the end of each item. but i do not know hot to link my checkbox's so that they add the item to  my basket in the data base taking the users id , name and barcode and name of the item.

 

The code that i have to search all DVD's in my data base its below:

 

<!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=utf-8" />

<title>Untitled Document</title>

 

<LINK rel="stylesheet" href="MyStyle.css" type="text/css">                                 

</head>

 

<body>

 

<center>

<table width="850px" border="0" cellspacing="0"cellpadding="5">

<tr>

        <td class="left" valign="top" rowspan="5"> <h1> Aston </h1></td>

<td class="top" colspan="5" height="60px"><h1> DVD Store</h1></td>

 

 

</tr>

<tr>

 

<td class="grey" colspan="5"></td>

</tr>

<tr>

 

<td class="links"> <a href="homepage.html"> Home </a></td>

<td class="links"> <a href="residential_lettings.html"> Residential Lettings </a> </td>

<td class="links"> <a href="enquiries.html"> Enquiries </a> </td>

<td class="links"> <a href="references.html"> References </a> </td>

    <td class="links"> </td>

</tr>

<tr>

 

<td class="text" colspan="5" align="center">

 

<h1><br>Search all DVD's</br></h1>

 

 

<form action="basket.php" method="post">

 

<p><input type="submit" name="submit" value="Go to Basket" onClick="window.location.href="add DVD.php""/></p>

 

</form>

<br>

<form action="search.php" method="post">

<input type="submit" value="Back to search" onClick="window.location.href="search.php"">

</form>

 

<?php

 

require_once ("mysql_connect.php");

 

 

 

///$genre = $_POST["genre"];

 

 

// Make the query.

$query = "select * from dvd order by DVDname";

//run the query

$result = mysql_query($query);

echo "Search Results<br/>";

 

echo "<table border='1' cellpadding ='10'>

<tr>

<th>Barcode</th>

<th>Dvd Title</th>

<th>Genre</th>

<th>Price</th>

<th>Quantity</th>

<th>Add to Basket</th>

<th>Add to Basket</th>

</tr>";

 

while($row = mysql_fetch_array($result))

  {

  echo "<tr>";

  echo "<td>" . $row['barcode'] . "</td>";

  echo "<td>" . $row['DVDname'] . "</td>";

  echo "<td>" . $row['genreName'] ."</td>";

  echo "<td>"."£" . $row['price'] . "</td>";

  echo "<td>". $row['quantity'] . "</td>";

  echo "<td>"."<form action='add DVD.php'>

<input type='submit' name='DVD' value='Add' >

</form>"."</td>";

echo "<td>"."<form method='POST'action= 'add DVD.php'><input type='checkbox' name='addtobasket' value='Add to Basket' />";

echo "</tr>";

  }

echo "</table>";

mysql_close();

?>

<!--<!--echo'<td class="text" width="10%" height="20">'<a href="basket1.php? action=addDVD & barcode= $row["barcode"];&quantity=1">Add Item</a>'</td>*/-->

 

 

<br>

 

<br>

</tr>

 

<!--echo "Quantity: ". $row["Quantity"] ."<br/>";-->

 

 

 

<br>

</td>

 

</tr>

 

<tr>

 

 

 

 

<td class="footer" colspan="6"><b>© Aston DVD Store </b> <font style="color=#666666; font-size=10;">The Aston Triangle, Birmingham, West Midlands B4 7EJ</font></td>

 

</tr>

 

</table>

</center>

</body>

</html>

Hi! I'm new on here so I'll just spout off:

 

I made a cart once by adding the information to a session var and then retrieving all the details for the item on checkout.

 

However, it looks like you are making a basket in a database.  Maybe when you echo the query results, you could echo them into input tags with thier name attributes and values, and submit your $_POST vars to your php script, inserting them into your database if($_POST['echoed_checkbox_name'] == "echoed_checkbox_value"), while looping through the $_POST array of course.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.