Jump to content

How can I make a Shopping cart using Mysql and PHP


mhillock89

Recommended Posts

Hello, I'm so stuck with this, I need major help on what I need to add to my code to make the items displayed from my database go into a cart which is displayed onto another page called cart.php. Here's the code I have so far...

 

This is the page which displays the items users can purchase (BooksLoggedIn.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=utf-8" />

<title>Student Books</title>

 

<link href="CSS.css" rel="stylesheet" type="text/css" />

 

</head>

<body>

 

<div id="PageContainer">

 

<div id="LogOut">

  <?php

require_once("dbconnect.php");

session_start();

if (isset($_SESSION['login']))

{

$username = $_SESSION['login'];

echo "<h4>User $username is logged in,  <a href='Books.php?'>Logout</a></h4>";

}

?>

</div>

 

 

<div id="cart">

<?php

//cart code here!

?>

</div>

 

 

 

 

  <div id="title">

    <h1>Computing - The Online Book store</h1>

  </div>

 

<div id="Search">

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

      <input type="text" name="txttitle">

      <input type="submit" name="btnSearch" value="Search"/>

  </form>

</div>

 

<div id="container">

  <table border="3" cellpadding="2" bordercolor="Grey">

   

  <tr>

   

    <td><h2>ID</h2></td>

    <td><h2>Title</h2></td>

    <td><h2>Price</h2></td>

    <td><h2>Add to basket</h2></td>

    <td><h2>Remove</h2></td>

   

   

  <tr>

   

<?php

 

require_once("dbconnect.php");

 

$query = "SELECT * FROM Books ORDER BY 'title'";

 

$dbRecords = mysql_query("SELECT * FROM Books", $dbConn)

    or die("Problem reading table: " +  mysql_error());

 

while ($arrRecords = mysql_fetch_array($dbRecords))

{

$id = $arrRecords["id"];

$title = $arrRecords["title"];

$price = $arrRecords["price"];

 

 

echo "<tr>";

echo "<td><h2>$id</h2></td>";

echo "<td><h2><a href = 'BookDetails.php?id=$id'>$title </a></h2></td>";

echo "<td><h2>£$price</h2></td>";

echo "<td><h2><a href='cart.php?action=add&id=1'>Add to cart</a></h2></td>";

echo "<td><h2><a href='cart.php?action=delete&id=1'>Remove</a></h2></td>";

 

echo "</tr>";

 

}

?>

 

  </table>

</div>

</div>

</div>

 

</body>

</html>

 

 

 

And this is all I have for my cart.php page:

 

<!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>

</head>

 

<body>

 

<?php

 

?>

 

<p><a href="BooksLoggedIn.php">Back to bookshop...</a></p>

 

</body>

</html>

 

Any help would be really appreciated, thanks :).

 

[attachment deleted by admin]

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.