Build a Shopping Cart With PHP Part-1
PROJECT OVERVIEW
In this project, you create the core features of a shopping cart. To get a clear idea of how the project works, take a look at the following use case: Hanif needs to buy some teabags for his mobile café. He goes to a popular online shop that was created by an owner of this very book. Hanif does not have a user account on the Web site but starts shopping anyway. He clicks the Beverages category and sees the list of teabags. He clicks the Buy link and is taken to another page, where he can choose the quantity. He selects 10 boxes of teabags and adds them to his shopping cart, he goes to websites like https://www.raise.com/coupons/target to see if there are any coupon codes avliable. The page now refreshes, and he sees the contents of his shopping cart. Hanif then buys coffee, and his cart is updated again. Hanif realizes he does not need the coffee after all, so he clicks the X link to delete the coffee from his cart. Hanif finishes choosing items and clicks the Go to the Checkout link. He is prompted for his address, which he fills in, and is taken to the payment screen. John can choose to pay with PayPal or by check. John clicks the PayPal button and taken to the PayPal payment screen at paypal.com, where he pays for the order.
Sangida needs some teabags, too. Sangida already has an account on the site, so she logs in. She adds the items she needs to her cart and clicks the Go to the Checkout link. At the address page, she can choose between a new address and the address stored with her user account. She chooses the account address and is taken to the payment screen. Sangida chooses to pay by check and is given instructions about where to send the check and to whom to make it payable. Always check and calculate your network security at http://subnet-calculator.org for free.
ShiShir runs the Web site and wants to see all current orders. He logs in with his administrator username and password and is provided with a list of orders.
ShiShir looks at each item, packages the order, and writes the address on the parcel. To confirm the completion of the order, ShiShir clicks the Confirm Payment link. The order is now complete.
The shopping cart you build in this chapter satisfies all of the features discussed in the preceding use case, but there is still a huge scope for development.
Shopping carts can become huge and complex systems, and an entire book would do the subject of building shopping carts justice. This project will provide a solid foundation in which you can continue to build in extra features.
BUILDING THE DATABASE
The database you will create is shown in Figure 1.
FIGURE 1-1 the database schema revolves around the main orders table.
This entire project fundamentally hinges on orders stored in the orders table.
This table relates to the customers (contains registered customer address details) and delivery_addresses (contains unregistered and alternative addresses) tables.
Each product (stored in the products table) in the order is stored in the order_items table. Other tables include logins (stores the registered user’s login details), categories (contains the categories that the products are part of), and admins (stores administrator login details).
Implementing the Database
Start phpMyAdmin, create a new database called go4shop, and add the following tables:
NOTE
Always Know Your Status
In the orders table is a field called status. The purpose of this field is to indicate at what point in the shopping cart the user has progressed. This field has four possible values:
0 | The user is still adding items to her shopping cart. |
1 | The user has entered her address. |
2 | The user has paid for the item. |
10 | The administrator has confirmed the transaction and sent the item. |
The admins Table
CREATE TABLE admin( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, `username` VARCHAR(100) NOT NULL, `password` VARCHAR(40) NOT NULL ) ENGINE = InnoDB;
The categories Table
CREATE TABLE categories( `id` TINYINT NOT NULL AUTO_INCREMENT PRIMARY KEY, `name` VARCHAR(100) NOT NULL) ENGINE = InnoDB;
The customers Table
CREATE TABLE customers( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, `forname` VARCHAR(50) NOT NULL, `surname` VARCHAR(50) NOT NULL, `add1` VARCHAR(50) NOT NULL, `add2` VARCHAR(50) NOT NULL, `add3` VARCHAR(50) NOT NULL, `postcode` VARCHAR(10) NOT NULL, `phone` VARCHAR(20) NOT NULL, `email` VARCHAR(150) NOT NULL, `registered` TINYINT NOT NULL ) ENGINE = InnoDB;
The delivery_addresses Table
CREATE TABLE delivery_addresses( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, `forname` VARCHAR(50) NOT NULL, `surname` VARCHAR(50) NOT NULL, `add1` VARCHAR(50) NOT NULL, `add2` VARCHAR(50) NOT NULL, `add3` VARCHAR(50) NOT NULL, `postcode` VARCHAR(10) NOT NULL, `phone` VARCHAR(20) NOT NULL, `email` VARCHAR(150) NOT NULL ) ENGINE = InnoDB;
The logins Table
CREATE TABLE logins( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, `customer_id` INT NOT NULL, `username` VARCHAR(100) NOT NULL, `password` VARCHAR(40) NOT NULL ) ENGINE = InnoDB;
The orderitems Table
CREATE TABLE orderitems( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, `order_id` INT NOT NULL, `product_id` INT NOT NULL, `quantity` INT NOT NULL ) ENGINE = InnoDB;
The orders Table
CREATE TABLE orders( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, `customer_id` INT NOT NULL, `registered` INT NOT NULL, `delivery_add_id` INT NOT NULL, `payment_type` INT NOT NULL, `date` DATETIME NOT NULL, `status` TINYINT NOT NULL, `session` VARCHAR(100) NOT NULL, `total` FLOAT NOT NULL) ENGINE = InnoDB;
The products Table
CREATE TABLE products ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, `cat_id` TINYINT NOT NULL, `name` VARCHAR(150) NOT NULL, `description` TEXT NOT NULL, `image` VARCHAR(30) NOT NULL, `price` FLOAT NOT NULL )ENGINE = InnoDB;
Insert Sample Data
With a solid set of tables ready to go, add some sample data to get started. Remember, do not fill in a number in the id column; this is handled by auto_increment.
Feel free to add your own sample data, or use the suggested information.
Sample Data for the admins Table
INSERT INTO admin (`id`, `username`, `password`) VALUES (NULL, 'shishir', SHA1('shishir123'));
Sample Data for the categories Table
INSERT INTO categories(`id`, `name`) VALUES (NULL, 'beverages'), (NULL, 'cakes');
Sample Data for the customers Table
INSERT INTO customers (`id`, `forname`, `surname`, `add1`, `add2`, `add3`, `postcode`, `phone`, `email`, `registered`) VALUES (NULL, 'Hamiduzzaman', 'parvez', 'Dhaka, Bangladesh', 'Gulshan 1', 'dkjf, lksd kl', '1200', '9879797', 'parvez@gmail.com', '1'), (NULL, 'Galib', 'Hossain', 'Dhaka', 'Coxbazar', 'Gulshan', '9879', '9898797', 'galib@gmail.com', '1');
Sample Data for the logins Table
Make sure you match the customer_id field to the id field in the customers table.
INSERT INTO `go4shop`.`logins` (`id`, `customer_id`, `username`, `password`) VALUES (NULL, '1', 'parvez', SHA1('parvez123')), (NULL, '2', 'galib', SHA1('galib123'));
Sample Data for the delivery_addresses Table
Leave this table empty.
Sample Data for the products Table
INSERT INTO products(`id`, `cat_id`, `name`, `description`, `image`, `price`) VALUES (NULL, '1', 'Best Bags', 'A quality pack of tea bags.200 bags in each box', '', '2.99'), (NULL, '1', 'Best Orange Juice', 'One gallon of quality sequeezed orange juice.', 'bestorange-juice.jpg', '0.9');
Sample Data for the orders Table
Leave this table empty.
Sample Data for the orderitems Table
Leave this table empty.
STARTING TO CODE
One of the challenges in creating a shopping cart is dealing with both registered and unregistered users. For registered users, there is no problem because, when adding information to the tables, you can use their IDs to track them. The challenge arises with unregistered users. How do you track them?
The solution is to use session IDs. When the user loads the first page with the session_start() function, a special session ID is generated. This ID is unique to that specific user and tracks which session variables are assigned to which user visiting the site. Although you have not referred to the session ID before, in this project you will use the session ID extensively.
Every time a user visits the shopping cart and adds his first item, an order is added to the orders table. For registered users, the user’s id is added to the customer_id field in the table. For unregistered users, the unique session id is added to the session field. When this order has been added to the table, a session variable called SESS_ORDERNUM is created with the id of the order. SESS_ORDERNUM can now be used to track the order’s progress throughout the site.
To get started, build the usual configuration file that stores generic information about the site. Create a new directory called go4shop and add the code shown in Example 1 to config.php.
<!--?php $dbhost = "localhost"; $dbuser = "root"; $dbpassword = ""; $dbdatabase = "go4shop"; $config_basedir = "http://localhost/go4shop/"; $config_sitename = "Go4Shop"; $db = mysql_connect($dbhost, $dbuser, $dbpassword); mysql_select_db($dbdatabase, $db); ?-->
Example 2.Create header.php as shown in Example 2.
EXAMPLE 2 The header file adds the menu options, includes the sidebar, and adds some login/logout links.
<!--?php session_start(); if(isset($_SESSION['SESS_CHANGEID']) == TRUE) { session_unset(); session_regenerate_id(); } require("config.php"); ?--> <!--?php echo $config_sitename; ?--> <div id="header"></div> <div id="menu"> <a href="<?php echo $config_basedir; ?>">Home</a> - <a href="<?php echo $config_basedir;?>showcart.php">View Basket/Checkout</a> </div> <div id="container"> <div id="bar"> <!--?php require("bar.php"); echo " <hr /--> "; if(isset($_SESSION['SESS_LOGGEDIN']) == TRUE) { echo "Logged in as <strong>" . $_SESSION['SESS_USERNAME']. "</strong>[<a href="' . $config_basedir. 'logout.php">logout</a>]"; } else{ echo "<a href="'. $config_basedir . 'login.php">Login</a>"; } ?> </div> <div id="main">
Take a moment to review the following interesting points about header.php:
■ At the top of the file, a check is made for a session variable called SESS_CHANGEID. If it exists, the session is unset (deleted) and the session id is regenerated. Later, when the order is complete, SESS_CHANGEID is created when the session system should be reset.
■ A check is made to see if the SESS_LOGGEDIN variable exists. If it does, it indicates the user is currently logged in, and his username and a Logout link are displayed. The username is stored in SESS_USERNAME; this variable is created in login.php, which is covered later.
■ Create css /stylesheet.css file for our shopping cart overall design shown in Example 3.
@charset "utf-8"; /* CSS Document */ body { font-family: "trebuchet ms", verdana, sans-serif; font-size: 12px; line-height: 1.5em; color: #333; background: #ffffff; margin: 0; padding: 0; text-align: center; width: 100%; } p { margin-top: 10px; } a:link { text-decoration: none; color: #000; } a:visited { text-decoration: none; border-bottom: 1px dotted #369; color: #000; } a:hover, a:active { text-decoration: none; border-bottom: 1px solid #036; color: #000; } img { border: 0; } #container { position: absolute; top: 85px; left: 0px; background: #ffffff; margin: 0 auto 0 auto; text-align: left; width: 100%; height: 100%; } #menu { font-family: "trebuchet ms", verdana, sans-serif; font-size: 14px; font-weight: bold; position: absolute; height: 27px; top: 60px; left: 0px; width: 100%; padding: 0px; color: #000000; background-color: #eee } #header { position: absolute; top: 0px; left: 0px; height: 60px; width: 100%; background: #333; padding-top: 8px; } #header h1 { font-size: 30px; text-transform: uppercase; letter-spacing: 0.3em; color: #fff; } #main { margin: 15px 15px 15px 240px; padding: 15px 15px 15px 15px; background: #FFFFFF; } #bar { float: left; width: 200px; background: #eee; z-index: 1; padding: 10px; margin-right: 30px; height: 100%; } #bar h1 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.3em; }
■ A file called bar.php is also included in the header file. This file contains the list of categories shown in Example 4.
EXAMPLE 4 Although the code in bar.php could have been added to header.php, you can use this file to cleanly add other content if needed.
Product Categories
$catsql = "SELECT * FROM categories;"; $catres = mysql_query($catsql); while($catrow = mysql_fetch_assoc($catres)){ echo "<a id="" href="' . $config_basedir. '/products.php?id=' . $catrow[">". $catrow['name'] . "</a>";}?>
The code in bar.php performs a SELECT query to gather all the categories and display them in an unordered list. Each category links to products.php, which is created later.
Create footer.php and add the code shown in Example 5.
EXAMPLE 5 The footer file adds admin links when the administrator is logged in.
<!--?php echo "<em-->All content on this site is © ". $config_sitename . ""; if(@$_SESSION['SESS_ADMINLOGGEDIN'] == 1) { echo "[<a href="' . $config_basedir . 'adminorders.php">admin</a>][<a href="'. $config_basedir. 'adminlogout.php">admin logout</a>]"; } ?>
Create the main index.php for site, using the code shown in Example 6.
EXAMPLE 6 It may come as a surprise to see such a minimal index.php file. This file is really intended for generic information about the store.
<!--?php require("header.php"); ?--> <h1>Welcome!!</h1> Welcome to the <strong></strong> <strong><!--?php echo $config_sitename; ?--> </strong><strong></strong> website. Click on one of the pages to explore the site. We have a wide range of different products available. <!--?php require("footer.php"); ?-->
With the main design complete, your browser should display something similar to Figure 2.
MANAGING USER LOGINS
Users are a critical element in a shopping cart, and tracking both registered and unregistered users is important. Many of the different scripts that form the site have two strands of functionality: one if the user is logged in and one if not.
Create a file called login.php and add the form:
<!--?php session_start(); require("config.php"); if(isset($_SESSION['SESS_LOGGEDIN']) == TRUE) { header("Location: " . $config_basedir); } if($_POST['submit']) { $loginsql = "SELECT * FROM logins WHERE username = '" . $_POST['userBox']. "' AND password = '" . sha1($_POST['passBox']) . "'"; $loginres = mysql_query($loginsql); $numrows = mysql_num_rows($loginres); if($numrows == 1) { $loginrow = mysql_fetch_assoc($loginres); session_register("SESS_LOGGEDIN"); session_register("SESS_USERNAME"); session_register("SESS_USERID"); $_SESSION['SESS_LOGGEDIN'] = 1; $_SESSION['SESS_USERNAME'] = $loginrow['username']; $_SESSION['SESS_USERID'] = $loginrow['id']; $ordersql = "SELECT id FROM orders WHERE customer_id = " . $_SESSION['SESS_USERID'] . " AND status < 2"; $orderres = mysql_query($ordersql); $orderrow = mysql_fetch_assoc($orderres); session_register("SESS_ORDERNUM"); $_SESSION['SESS_ORDERNUM'] = $orderrow['id']; header("Location: " . $config_basedir); } else { header("Location: http://" .$_SERVER['HTTP_HOST']. $_SERVER['SCRIPT_NAME'] . "?error=1"); } } else { require("header.php"); ?--> <h1>Customer Login</h1> Please enter your username and password to log into the websites. If you do not have an account, you can get one for free by <a href="register.php">registering</a>. <!--?php if(isset($_GET['error'])) { echo "<strong-->Incorrect username/password"; } ?> <form action="<?php $_SERVER['SCRIPT_NAME']; ?>" method="POST"> <table> <tbody> <tr> <td>Username</td> <td><input type="textbox" name="userBox"></td> </tr> <tr> <td>Password</td> <td><input type="password" name="passBox"></td> </tr> <tr> <td></td> <td><input type="submit" name="submit" value="Log in"></td> </tr> </tbody> </table> </form><!--?php } require("footer.php"); ?-->
Take a moment to review the following interesting points about login.php:
Move to the start of the file and begin adding the code:
<!--?php session_start(); require("config.php"); if(isset($_SESSION['SESS_LOGGEDIN']) == TRUE) { header("Location: " . $config_basedir); }
A check is made to see if the user is already logged in. If so, there is no point in loading the login page, so the page redirects to the base URL of the site.
Process the form:
if(isset($_SESSION['SESS_LOGGEDIN']) == TRUE) { header("Location: " . $config_basedir); } if($_POST['submit']) { $loginsql = "SELECT * FROM logins WHERE username = '" . $_POST['userBox'] . "' AND password = '" . $_POST['passBox'] . "'"; $loginres = mysql_query($loginsql); $numrows = mysql_num_rows($loginres); if($numrows == 1) { $loginrow = mysql_fetch_assoc($loginres); session_register("SESS_LOGGEDIN"); session_register("SESS_USERNAME"); session_register("SESS_USERID"); $_SESSION['SESS_LOGGEDIN'] = 1; $_SESSION['SESS_USERNAME'] = $loginrow['username']; $_SESSION['SESS_USERID'] = $loginrow['id']; $ordersql = "SELECT id FROM orders WHERE customer_id = " . $_SESSION['SESS_USERID'] . " AND status < 2"; $orderres = mysql_query($ordersql); $orderrow = mysql_fetch_assoc($orderres); session_register("SESS_ORDERNUM"); $_SESSION['SESS_ORDERNUM'] = $orderrow['id']; header("Location: " . $config_basedir); } else { header("Location: http://" .$_SERVER['HTTP_HOST']. $_SERVER['SCRIPT_NAME'] . "?error=1"); } } ?-->
This code uses the same technique shown earlier for logging in a user. When a successful login occurs, three session variables are created:
■ SESS_LOGGEDIN. Set to 1 to indicate the user is currently logged in.
■ SESS_USERNAME. Contains the username of the user.
■ SESS_USERID. Contains the id of the user.
In addition to these variables, a SELECT statement pulls the id from the orders table, in which the customer_id field matches the id of the current user. Another session variable called SESS_ORDERNUM is then set to the id returned from this query.
This process can have one of two outcomes:
■ No order exists. If no order exists in the orders table, SESS_ORDERNUM is not set to anything.
■ An order exists. If an id is returned from the query, SESS_ORDERNUM is set to this id. This is useful if the user was selecting items for the shopping cart and then logged out. When the user logs in again, the shopping cart contains the same items from the previous visit and the user can continue to select items. This functionality provides some important continuity.
When the form is successfully submitted and the session variables are set, the page redirects to the base URL of the site. The page will display the text Logged in as in the sidebar.
Finally, add the code after the form:
else { require("header.php"); ?> <h1>Customer Login</h1> Please enter your username and password to log into the websites. If you do not have an account, you can get one for free by <a href="register.php">registering</a>. <!--?php if(isset($_GET['error'])) { echo "<strong-->Incorrect username/password"; } ?> <form action="<?php $_SERVER['SCRIPT_NAME']; ?>" method="POST"> <table> <tbody> <tr> <td>Username</td> <td> <input type="textbox" name="userBox"></td> </tr> <tr> <td>Password</td> <td> <input type="password" name="passBox"></td> </tr> <tr> <td></td> <td> <input type="submit" name="submit" value="Log in"></td> </tr> </tbody> </table> </form><!--?php } require("footer.php"); ?-->
The completed results should look similar to the page shown in Figure 3.
FIGURE 3 The completed login screen
Logging Out Users
With the user now able to log in, you also need to give him the ability to log out by destroying the session created on login. Create a new file called logout.php and add the following code:
<!--?php session_start(); require("header.php"); require("config.php"); unset($_SESSION['SESS_LOGGEDIN']); unset($_SESSION['SESS_USERNAME']); unset($_SESSION['SESS_USERID']); session_destroy(); header("Location: " . $config_basedir); require("footer.php"); ?-->
DISPLAYING AND SELECTING PRODUCTS
The most central function of a shopping cart is to show the user a range of products and allow her to choose products, adding them to the metaphorical shopping cart. This involves a few different processes:
■ The user clicks a product category to view available products. To choose a product, she clicks the Buy link.
■ Next, the user selects the quantity of items.
■ The page displays the current contents of the shopping cart and total price.
The user can also click the X symbols to delete any items from the cart and recalculate the total.
The first step in this process is to display the available products within a category.
Before you begin creating the code, you need to use the pf_validate_number() function for number validation. Create a new file called functions.php and copy the code into it:
<!--?php function pf_validate_number($value, $function, $redirect) { if(isset($value) == TRUE) { if(is_numeric($value) == FALSE) { $error = 1; } if($error == 1) { header("Location: " . $redirect); } else { $final = $value; } } else { if($function == 'redirect') { header("Location: " . $redirect); } if($function == "value") { $final = 0; } } return $final; } ?-->
For this project, you should also create some product images, such as those shown in Figure 4, for use with your shopping cart. You need to create at least one image, called dummy.jpg in your productimages folder, that can be loaded when no image exists for a product. If you used the sample data earlier in this chapter, the image for the Best Orange Juice product is called bestorangejuice.jpg in your productimages folder.
FIGURE 4 Each image should be 150×150 in size and saved as a JPG.
Create a new file called products.php
<!--?php require("config.php"); require("functions.php"); $validid = pf_validate_number($_GET['id'],"redirect", $config_basedir); require("header.php"); $prodcatsql = "SELECT * FROM products WHERE cat_id = " . $_GET['id'] . ";"; $prodcatres = mysql_query($prodcatsql); $numrows = mysql_num_rows($prodcatres); if($numrows == 0) { echo " <h1-->No products "; echo "There are no products in this category."; } else{ echo ""; while($prodrow = mysql_fetch_assoc($prodcatres)){ echo ""; if(empty($prodrow['image'])) { echo ""; } else { echo ""; } echo ""; echo ""; } echo " tbody> <table cellpadding="10"> <tbody> <tr> <td><img src="./productimages/dummy.jpg" alt="'. $prodrow[" name=""></td> <td><img src="./productimages/' . $prodrow[" alt="'. $prodrow[" name=""></td> <td>"; echo " <h2>" . $prodrow['name'] . "</h2> "; echo "" . $prodrow['description']; echo "<strong>OUR PRICE: £". sprintf('%.2f', $prodrow['price']) . "</strong>"; echo "[<a id="" href="addtobasket.php?id='. $prodrow[">buy</a>]"; echo "</td> </tr> </tbody> </table> "; } require("footer.php"); ?>
Now we explain the code:
<!--?php require("config.php"); require("functions.php"); $validid = pf_validate_number($_GET['id'],"redirect", $config_basedir);
The pf_validate_number() function validates the category id GET variable that is passed to the page. If no id GET variable exists, the function redirects to the site’s base URL.
Select the products from the database:
require("header.php"); $prodcatsql = "SELECT * FROM products WHERE cat_id = " . $_GET['id'] . ";"; $prodcatres = mysql_query($prodcatsql); $numrows = mysql_num_rows($prodcatres); if($numrows == 0) { echo " <h1-->No products "; echo "There are no products in this category."; }
If a category has no products, the text No products is displayed on the page. (To determine whether a category has projects, check if the number of rows returned is 0.) If a category contains products, a while() loop iterates through each row:
else { echo ""; while($prodrow = mysql_fetch_assoc($prodcatres)){ echo ""; if(empty($prodrow['image'])) { echo ""; } else { echo ""; } echo ""; echo ""; } echo " <table cellpadding="10"> <tbody> <tr> <td><img src="./productimages/dummy.jpg" alt="' . $prodrow[" name=""></td> <td><img src="./productimages/' . $prodrow[" alt="'. $prodrow[" name=""></td> <td>"; echo " <h2>" . $prodrow['name'] . "</h2> "; echo "" . $prodrow['description']; echo "<strong>OUR PRICE: £". sprintf('%.2f', $prodrow['price']) . "</strong>"; echo "[<a id="" href="addtobasket.php?id=' . $prodrow[">buy</a>]"; echo "</td> </tr> </tbody> </table> "; ?>
The information about each product is displayed, and a Buy link is linked to addtobasket.php. The link also passes the id of the product as a GET variable.
Finally, add the closing code:
} require("footer.php"); ?>
The completed results should look similar to the page shown in Figure 5.
The completed results should look similar to the page shown in Figure 5.
Parse error: syntax error, unexpected ‘.’ in C:\wamp\www\go4shop\header.php on line 2
i got error with this.. can you help me?
its line 27 im sorry.
did you figure it out
I am also getting the same error…..
did anyone figure it out..
First i wanna thank for the great tutorial Mr Masoud.
Here is the problem :
Replace This with the ones in the code =>
if(isset($_SESSION[‘SESS_LOGGEDIN’]) == TRUE)
{
echo ‘Logged in as ‘ . $_SESSION[‘SESS_USERNAME’] . “[logout]”;
}
else{
echo “Login“;
}
And this one also : =>
if(@$_SESSION[‘SESS_ADMINLOGGEDIN’] == 1)
{
echo “[admin][admin logout]”;
}
anyone know admin login id and password?
remove decryption part in lodin.php (sha1) and in database modify login table with your own password.
user: james
pass: james123
First i wanna thank for the great tutorial Mr Masoud.
Here is the problem :
Replace This with the ones in the code =>
if(isset($_SESSION[‘SESS_LOGGEDIN’]) == TRUE)
{
echo ‘Logged in as ‘ . $_SESSION[‘SESS_USERNAME’] . “[logout]“;
}
else{
echo “Login“;
}
And this one also : =>
if(@$_SESSION[‘SESS_ADMINLOGGEDIN’] == 1)
{
echo “[admin][admin logout]“;
}
Hi sir after i make the changes in header.php
as
if(isset($_SESSION[‘SESS_LOGGEDIN’]) == TRUE)
{echo “Logged in as”. $_SESSION[‘SESS_USERNAME’]. “[logout]“;
}
else
{
echo “Login“;
}
i m getting this error
Parse error: parse error, expecting `’,” or `’;” in C:\wamp\www\go4shop\header.php on line 27
pls help
hi sir,
i need your help urgently.
Notice: Undefined index: id in E:\xampp\htdocs\products.php on line 11
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in E:\xampp\htdocs\products.php on line 15
i dont know where is the fault.i hope to hear from you soon.thank you
plz insert some sample data to your table
Hi Masud , great gode very helpful. I am new to php and while executing index.php i get the following error
Parse error: syntax error, unexpected ‘.’ in /home/savsca/public_html/test/D/header.php on line 28
I would really appreciate if you could get your help on this.
hi masud alam, how to login to admin? what is the id and password for admin login?
Hey, nice post and nice blog! Can you create a shopping cart object oriented?
hello sir i just learnd php short cource and i know little bit about it can this pos post is help full for me for making shopping cart? plz tell me
sir it didn’t work :O
Hello,
I have studied the above full code & I started working on it,
When I run the project (localhost/go4shop). It gave me lot of errors. Which I rectified, but I found that some files are missed out in this tutorial like (‘showcart.php’, ‘addtobasket.php’). If you can, please provide me with the files.
Thanks & regards,
Srinivasu.M
http://www.w3programmers.com/build-a-shopping-cart-with-php-part-2/
Sorry i have done some mistake in asking question.
I am getting some error during data insertion in table customers.
Please help me.
Error are here
#1064 – You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘data-cfemail’);if(a){s=”;r=parseInt(a.substr(0,2),16);for(j=2;a.length-j;j+=2){‘ at line 3
How dowload ?
Hey frndz ! i need a help. if any one have easy and efficient code of Shoping cart that is proper worked. then please send me at muhammadrabeet@gmail.com
i need this code for my website. plzz help me !
Fantastic tutorial.. Got a question. is the login system required in it, as in does the user have to login/register to buy things
Thanks
thanks, I am building this kind of shopping cart too now for my computer course and these are good instructions, I wish I’d be more skilled with SQL though
Hello
Thank you for making this tutorial available to us. Also we would appreciate if you can make available for download the files used in this tutorial, as when following this tutorial and the next tutorial to complete the project; I am getting a lot of errors and I am unable to correct all of them.
Thank you
Hi
Trying to get this cart to work from the instructions and I keep coming across issues with the connections/ showing of the results of tables info due to "
How do I get around this as I have fixed the header but then I have got the same issue on footer and products
Thanks in advance
Martyn
Parse error: syntax error, unexpected ‘” href=”‘ (T_CONSTANT_ENCAPSED_STRING), expecting ‘,’ or ‘;’ in C:\wamp\www\go4shop\bar.php on line 5
i got error with this.. can you help me?
this is the code in bar.php:
echo ““. $catrow[‘name’] . ““;
Some serious issues, but fixed all of them, also noticed some unnescary code, alot of the includes for config.php can be delete, also sessions() aren’t used in PHP 5.4 anymore. But once all of it is working, its a good little system. Im working to expand this and bring it up to date, i got a fully working system now.
Can you help me with this problem?
Parse error: syntax error, unexpected ‘.’ in /Applications/XAMPP/xamppfiles/htdocs/VACO/header.php on line 27
after i make the changes in header.php
if(isset($_SESSION[‘SESS_LOGGEDIN’]) == TRUE)
{echo “Logged in as”. $_SESSION[‘SESS_USERNAME’]. “[logout]“;
}
else
{
echo “Login“;
}
still don’t work
hi.. do you have the missing register.php file?
can u email me at:
kristinmaee12@gmail.com
thanks
Hi, did you ever get a copy of the register page?
make it work pal
Parse error: syntax error, unexpected ‘.’ in /Applications/XAMPP/xamppfiles/htdocs/VACO/header.php on line 27
any solution?
Could you please tell me where to add the admin login link ? footer file will show the admin related links only after admin get logged in. I dont see any link calling the admin login file.
Hi
Could you please tell me how to add an update for product stock that have sold?
Thanks.
Hi,
Could you please tell me how to update the stock product when admin has confirm the payment?
hey thanks for the tutorial but am having an error at this point
{
echo “Logged in as ” . $_SESSION[‘SESS_USERNAME’]. “[logout]”;
}
{
echo “Logged in as ” . $_SESSION[‘SESS_USERNAME’]. “[logout]”;
}
am finding an error at this part
Hi,
please help me for linking the login to login.php..
And also i got an error on product.php
The code is echo”
… It doesn’t display the product table .. So please help me..
Notice: Undefined index: id in C:\wamp\www\products.php on line 6
i got this error while running the product.php code
need some help
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\wamp\www\products.php on line 8
got this error again in the same file code “product.php”
some one make me clear
C:\wamp\www\products.php on line 8 undefined index id error pls help…
Hi, login.php line #37 broken linkregistering.
register.php is missing.
BR
i want to take some in zend cart. so tell me when you come online. and what is your email and skype id
Regards
Tanveer Abbas
Here is my company skype: techbeeo
and my personal email: masud.eden@gmail.com
Hi this is my email:
kristinmaee12@gmail.com
can you pls send me the register.php file? because it was missing 🙂 Best regards 🙂
hi. i am using a hosting company and they dont provide a database. can i use sql server 2008. The reason i am using the hosting company site creator.
hi MASUD ALAM 🙂
Can i have the register.php file??
because it’s missing 🙂 thank you..
Best regards,
Chris
hi masud 🙂 i have inbox you in your mail 🙂
this is my email..
kristinmaee12@gmail.com
THANK YOU SO MUCH 🙂
Hi
can you pls send me the register.php file? because it’s missing
this is my email:
david.menesesv@gmail.com
Best regards
Sir,
There’s missing register.php file.Can i get the file?.My mail id is sami.cse.1112@gmail.com.
Thank You Sir
Hi this is my email:
albertkwokmk@gmail.com
can you pls send me the register.php file? because it was missing 🙂 Best regards 🙂
Hi, here is my email:
albertkwokmk@gmail.com
can you pls send me the register.php file? because it was missing 🙂 Best regards 🙂
Could you please send file “register.php”? It is missing from the project code.
Thanks a lot brother.
Id: mr9876540@gmail.com
Thanks for the awesome Helpful….
register.php file missing ??
please send me..
THANK YOU SO MUCH 🙂
pawarmanali1999@gmail.com
register.php file missing ??
please send me..
THANK YOU SO MUCH 🙂
I’m looking for the register.php page code, anyone have it?
My email is dexter.gibons@gmail.com
me too
Pingback: Php Shopping Cart Paypal | Home
Pingback: Free Php Shopping Cart Script | Home
Pingback: Shopping Cart Php Script |
thanks for this tutorial very good i have also read another tutorial on same topic for creating shopping cart with php and mysql http://talkerscode.com/webtricks/simple-add-to-cart-system-using-jquery-ajax-and-php.php
Pingback: Bootstrap Shopping Cart | emergingloan.com
I just change config.php file all errors are solved
contact me for the php file
my email-id rishadb7@gmail.com
HI,
can you send me the register.php file on arjun6chopra@gmail.com
Hi.
Thanks for the tutorial. It’s very helpful. but I’m looking for the register.php page code, anyone have it?
Salam, I have a question. I have set up the code and database in my laptop properly.However , I cannot login into the website as admin. Can someone answer me?
Pingback: Paypal Shopping Cart Example |
sir,please send me register.php file
Please could i have a copy of the register.php file please?
walford2141@hotmail.com
hi, awesome guide man! very helpful
can you please send me the register.php file. race512@hotmail.com
thanks a lot in advance
Rafael
Hi,
I also need the copy of register.php.
My email ID is arjun6chopra@gmail.com
can you please send me the register.php file.
I also need the copy of register.php
please send me register.php file
I don’t even know how I finished up here, but
I thought this submit was great. I don’t recognize who you’re
however certainly you’re going to a well-known blogger when you are
not already. Cheers!
What is the admin I’d and password?
can I have register.php file please
Hi there very nice website!! Man .. Beautiful ..
Wonderful .. I’ll bookmark your web site and take the feeds also?
I’m glad to find so many useful information right here within the post, we’d like work out extra techniques on this regard, thank you for sharing.
. . . . .
I hv a register.php file..
Anyone know the admin login ID n password?
Because I try login shishir I’d and password shishir123 it can’t use
Here you go REGISTER.PHP…But is there anybody who fixed errors,there are differences between this online code and download source code
Registracija korisnika
Molimo Vas unesite Vaš username i password kako biste se resgistrovali.
<?php
if(isset($_GET['submit'])) {
echo "Y“;
}
?>
<form action="” method=”POST”>
Username
Password
Registracija korisnika
Molimo Vas unesite Vaš username i password kako biste se registrovali.
<?php
if(isset($_GET['submit'])) {
echo "Y“;
}
?>
<form action="” method=”POST”>
Username
Password
Hello, Wish to part of your forum. I also wish to learn more about web applications with PHP. I have a considerable knowledge on PHP and Database, I have done the basis of software engineering specialising in what you are doing here
Thank you for the source code of registered users. How can I make non-registered users buy products from site?
i got this message..
Fatal error: Call to undefined function session_register() in C:\xampp\htdocs\trainees\yamini\go4shop\login.php on line 15
please send register.php file
pleaser send register.php
or please send sourcr code for shopping cart website if anyone have in php
The login.php and the adminlogin.php do not work even if you have entered the correct accurate data from the database to login in. i entered the correct details from the database and It still does not work. It keeps saying “Incorrect username/password” even if i entered the exact data from the database. Please help?
Sir please can you help me with creating a datbase for this i even dont know 2 do this
please send register.php file
Fatal error: Uncaught Error: Call to undefined function mysql_connect() in C:\xampp\htdocs\Go4Shop\config.php:8 Stack trace: #0 C:\xampp\htdocs\Go4Shop\login.php(3): require() #1 {main} thrown in C:\xampp\htdocs\Go4Shop\config.php on line 8
help me! to fix please !!!!!
Thank you for this tutorial. But I wish you teach me how to display news article in category in my website.
i have running but you forget to upload some files like register.php, adminorders.php, and adminlogout.php, can you brig it for us?