├── .DS_Store ├── Database SQL File ├── .DS_Store └── sonicTechStore.sql ├── PHP Files ├── .DS_Store ├── checkout.php ├── contact.php ├── dbconnect.php ├── footer.php ├── header.php ├── home.php ├── index.php ├── ipadair.png ├── ipadpro.png ├── iphone7.png ├── iphone7s.png ├── logout.php ├── macbookair.png ├── macbookpro.png ├── menu.php ├── orderResult.php ├── product.php ├── register.php ├── shop.php ├── style.css ├── success.php └── yourcart.php └── README.md /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoanganhkhoil/PHP-MySQL-Shopping-Website/4d7278dc4128221085b31b8229426b0a770ab820/.DS_Store -------------------------------------------------------------------------------- /Database SQL File/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoanganhkhoil/PHP-MySQL-Shopping-Website/4d7278dc4128221085b31b8229426b0a770ab820/Database SQL File/.DS_Store -------------------------------------------------------------------------------- /Database SQL File/sonicTechStore.sql: -------------------------------------------------------------------------------- 1 | -- phpMyAdmin SQL Dump 2 | -- version 4.5.2 3 | -- http://www.phpmyadmin.net 4 | -- 5 | -- Host: localhost 6 | -- Generation Time: Apr 28, 2017 at 11:40 PM 7 | -- Server version: 10.1.19-MariaDB 8 | -- PHP Version: 5.6.28 9 | 10 | SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; 11 | SET time_zone = "+00:00"; 12 | 13 | 14 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; 15 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; 16 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; 17 | /*!40101 SET NAMES utf8mb4 */; 18 | 19 | -- 20 | -- Database: `sonicTechStore` 21 | -- 22 | 23 | -- -------------------------------------------------------- 24 | 25 | -- 26 | -- Table structure for table `Customers` 27 | -- 28 | 29 | CREATE TABLE `Customers` ( 30 | `customerID` int(11) NOT NULL, 31 | `userName` varchar(150) NOT NULL, 32 | `userPassword` varchar(150) NOT NULL, 33 | `customerName` varchar(150) NOT NULL, 34 | `customerAddress` varchar(250) NOT NULL, 35 | `customerPhone` varchar(25) NOT NULL, 36 | `customerEmail` varchar(150) NOT NULL 37 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 38 | 39 | -- 40 | -- Dumping data for table `Customers` 41 | -- 42 | 43 | INSERT INTO `Customers` (`customerID`, `userName`, `userPassword`, `customerName`, `customerAddress`, `customerPhone`, `customerEmail`) VALUES 44 | (4, 'admin', '$2y$10$Tie25.ymNVYejl6ggDsIieA70ZeDL54iBiDdicE05ufCuUhLZhpha', 'Khoi Hoang', '12 Sandra Ct', '2407162326', 'hoang@gmail.com'); 45 | 46 | -- -------------------------------------------------------- 47 | 48 | -- 49 | -- Table structure for table `Products` 50 | -- 51 | 52 | CREATE TABLE `Products` ( 53 | `productID` int(11) NOT NULL, 54 | `productName` varchar(50) NOT NULL, 55 | `productPrice` double(10,2) NOT NULL, 56 | `productImage` varchar(250) NOT NULL 57 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 58 | 59 | -- 60 | -- Dumping data for table `Products` 61 | -- 62 | 63 | INSERT INTO `Products` (`productID`, `productName`, `productPrice`, `productImage`) VALUES 64 | (1, 'Iphone 7', 699.00, 'iphone7.png'), 65 | (2, 'Iphone 7s', 799.00, 'iphone7s.png'), 66 | (3, 'Ipad Air', 599.00, 'ipadair.png'), 67 | (4, 'Ipad Pro', 899.00, 'ipadpro.png'), 68 | (5, 'Macbook Air', 999.00, 'macbookair.png'), 69 | (6, 'Macbook Pro', 1399.00, 'macbookpro.png'); 70 | 71 | -- 72 | -- Indexes for dumped tables 73 | -- 74 | 75 | -- 76 | -- Indexes for table `Customers` 77 | -- 78 | ALTER TABLE `Customers` 79 | ADD PRIMARY KEY (`customerID`); 80 | 81 | -- 82 | -- Indexes for table `Products` 83 | -- 84 | ALTER TABLE `Products` 85 | ADD PRIMARY KEY (`productID`); 86 | 87 | -- 88 | -- AUTO_INCREMENT for dumped tables 89 | -- 90 | 91 | -- 92 | -- AUTO_INCREMENT for table `Customers` 93 | -- 94 | ALTER TABLE `Customers` 95 | MODIFY `customerID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5; 96 | -- 97 | -- AUTO_INCREMENT for table `Products` 98 | -- 99 | ALTER TABLE `Products` 100 | MODIFY `productID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7; 101 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; 102 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; 103 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; 104 | -------------------------------------------------------------------------------- /PHP Files/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoanganhkhoil/PHP-MySQL-Shopping-Website/4d7278dc4128221085b31b8229426b0a770ab820/PHP Files/.DS_Store -------------------------------------------------------------------------------- /PHP Files/checkout.php: -------------------------------------------------------------------------------- 1 | alert("Your cart is empty.")'; 10 | echo ''; 11 | } 12 | 13 | //Check if user already logged in. Jump to orderResult.php page. Otherwise, show log in require. 14 | else if (isset($_SESSION['userSession'])!="") { 15 | header("Location: orderResult.php"); 16 | exit; 17 | } 18 | ?> 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |

Sorry you will have to log in first.

27 |

Click here to log in

28 | 29 | -------------------------------------------------------------------------------- /PHP Files/contact.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | alert("Successfully send message")'; 15 | echo ''; 16 | } 17 | ?> 18 | 19 |
20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 45 | 46 | 47 | 48 | 49 | 50 |

If you wish to contact us, send us an email.

Your name:
Telephone:
Email address:
Message: 44 |
51 |
52 |
53 | 54 | 55 | -------------------------------------------------------------------------------- /PHP Files/dbconnect.php: -------------------------------------------------------------------------------- 1 | connect_errno) { 8 | die ("Error: ". $DBcon->connect_error); 9 | } 10 | ?> -------------------------------------------------------------------------------- /PHP Files/footer.php: -------------------------------------------------------------------------------- 1 | 2 |
4 |

Sonic Tech Store.
4200 Connecticut Ave NW, Washington, DC 20008

5 | 6 |
7 | 8 | 9 | -------------------------------------------------------------------------------- /PHP Files/header.php: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | buy 7 | 8 | 9 | 10 | 46 | 47 | 48 |
49 |
50 |

SONIC TECH STORE

51 |
52 | -------------------------------------------------------------------------------- /PHP Files/home.php: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 10 |

Welcome to the home of Sonic Tech Store. 11 |

12 | 13 |

We offer customers in countries where Apple Store is not available the best price to buy Apple products. 14 |

15 | 16 | 17 | -------------------------------------------------------------------------------- /PHP Files/index.php: -------------------------------------------------------------------------------- 1 | real_escape_string($userName); 21 | $userPass = $DBcon->real_escape_string($userPass); 22 | 23 | 24 | //Getting user information by using username. Then compare password. 25 | $query = $DBcon->query("SELECT customerID, userName, userPassword FROM Customers WHERE userName='$userName'"); 26 | $row=$query->fetch_array(); 27 | 28 | //If user exists. $count must = 1. 29 | $count = $query->num_rows; 30 | 31 | //Check if password is correct or not. If match, show success page. 32 | if (password_verify($userPass, $row['userPassword']) && $count==1) { 33 | $_SESSION['userSession'] = $row['customerID']; 34 | header("Location: success.php"); 35 | } 36 | 37 | 38 | //If password not match, show error. 39 | else { 40 | $msg = "
41 |

  Invalid Username or Password !

42 |
"; 43 | } 44 | $DBcon->close(); 45 | } 46 | ?> 47 | 48 | 49 | 50 | 51 | 52 |
53 |
54 | 55 |

Sign In.

56 | 57 |
58 | 59 | 60 | 65 |
66 | 67 | 68 |
69 | 70 | 71 |
72 | 73 |
74 | 75 |
76 | 77 |
78 | 81 | 82 |
83 |
84 | Do not have an account? Click here to sign up! 85 | 86 |
87 | 88 |
89 | 90 | -------------------------------------------------------------------------------- /PHP Files/ipadair.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoanganhkhoil/PHP-MySQL-Shopping-Website/4d7278dc4128221085b31b8229426b0a770ab820/PHP Files/ipadair.png -------------------------------------------------------------------------------- /PHP Files/ipadpro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoanganhkhoil/PHP-MySQL-Shopping-Website/4d7278dc4128221085b31b8229426b0a770ab820/PHP Files/ipadpro.png -------------------------------------------------------------------------------- /PHP Files/iphone7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoanganhkhoil/PHP-MySQL-Shopping-Website/4d7278dc4128221085b31b8229426b0a770ab820/PHP Files/iphone7.png -------------------------------------------------------------------------------- /PHP Files/iphone7s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoanganhkhoil/PHP-MySQL-Shopping-Website/4d7278dc4128221085b31b8229426b0a770ab820/PHP Files/iphone7s.png -------------------------------------------------------------------------------- /PHP Files/logout.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 28 |
-------------------------------------------------------------------------------- /PHP Files/orderResult.php: -------------------------------------------------------------------------------- 1 | query("SELECT customerName, customerAddress, customerPhone, customerEmail FROM Customers WHERE customerID='$id'"); 14 | $row = $query->fetch_array(); 15 | 16 | $name = $row['customerName']; 17 | $address = $row['customerAddress']; 18 | $phone = $row['customerPhone']; 19 | $email = $row['customerEmail']; 20 | ?> 21 | 22 | 23 | 24 | 25 | 26 | Order processed at ".date('H:i, jS F Y')."

"; 28 | 29 | echo "

Receiver: $name

" ; 30 | 31 | echo "

Shipping address: $address

" ; 32 | 33 | echo "

Phone number: $phone

" ; 34 | 35 | echo "

Email address: $email

" ; 36 | 37 | 38 | 39 | echo "

Your order is as follows:

"; 40 | 41 | $total = 0; 42 | 43 | 44 | //If cart is not empty. Display item. 45 | if(!empty($_SESSION["cart"])) 46 | { 47 | 48 | foreach($_SESSION["cart"] as $keys => $values) 49 | { 50 | echo '
'; 51 | echo '
'; 52 | echo '

Item ordered: '. $values["item_name"]. '

'; 53 | echo '

Quantity: '. $values["item_quantity"]. '

'; 54 | echo '

Price: '. $values["product_price"]. '

'; 55 | echo '
'; 56 | echo '
'; 57 | 58 | $total = $total + ($values["item_quantity"] * $values["product_price"]); 59 | } 60 | 61 | } 62 | 63 | ?> 64 | 65 | 66 | 67 |
68 |
69 |
70 |

Sub total: $

71 |

Tax: $

72 |

Total: $

73 |
74 |

Thank you for ordering at Sonic Tech Store!

75 |

Click here to continue shopping

76 | 77 |
78 |
79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /PHP Files/product.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | 11 | 12 | 13 | query($query); 18 | if($result->num_rows > 0) 19 | { 20 | while($row = $result->fetch_array()) 21 | { 22 | ?> 23 |
24 |
"> 25 |
26 | "> 27 |
28 |
$
29 | 30 | "> 31 | "> 32 | 33 |
34 |
35 |
36 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /PHP Files/register.php: -------------------------------------------------------------------------------- 1 | real_escape_string($userName); 26 | $userPass = $DBcon->real_escape_string($userPass); 27 | $customerName = $DBcon->real_escape_string($customerName); 28 | $customerAddress = $DBcon->real_escape_string($customerAddress); 29 | $customerPhone = $DBcon->real_escape_string($customerPhone); 30 | $customerEmail = $DBcon->real_escape_string($customerEmail); 31 | 32 | 33 | 34 | $hashed_password = password_hash($userPass, PASSWORD_DEFAULT); // this function works only in PHP 5.5 or latest version 35 | 36 | //To check if username or email has not been taken. 37 | $check_username = $DBcon->query("SELECT customerEmail FROM Customers WHERE userName='$userName'"); 38 | $check_email = $DBcon->query("SELECT customerEmail FROM Customers WHERE customerEmail='$customerEmail'"); 39 | 40 | $count=$check_email->num_rows + $check_username->num_rows; 41 | 42 | //count = 0 means both email and username not registed yet. Can use. 43 | if ($count==0) { 44 | 45 | $query = "INSERT INTO Customers(userName,userPassword,customerName,customerAddress,customerPhone,customerEmail) VALUES('$userName','$hashed_password','$customerName','$customerAddress','$customerPhone','$customerEmail')"; 46 | 47 | if ($DBcon->query($query)) { 48 | $msg = "
49 |

  Successfully registered !

50 |
"; 51 | } 52 | 53 | else { 54 | $msg = "
55 |

  error while registering !

56 |
"; 57 | } 58 | 59 | } 60 | 61 | //Otherwise, email is already taken. Cannot use. 62 | else { 63 | 64 | 65 | $msg = "
66 |

  Sorry email or username already taken !

67 |
"; 68 | 69 | } 70 | 71 | $DBcon->close(); 72 | } 73 | ?> 74 | 75 | 76 | 77 | 78 | 79 |
80 | 81 |
82 | 83 |

Sign Up

84 | 85 |
86 | 87 | 92 | 93 |
94 | 95 |
96 | 97 | 98 |
99 | 100 |
101 | 102 | 103 |
104 | 105 | 106 |
107 | 108 | 109 |
110 | 111 |
112 | 113 | 114 |
115 | 116 |
117 | 118 | 119 |
120 | 121 |
122 | 123 | 124 | 125 |
126 | 127 | 128 |
129 |
130 | 133 |
134 |
135 | Already have an account? Click here to log in 136 |
137 | 138 |
139 | 140 | 141 | 142 | 143 | -------------------------------------------------------------------------------- /PHP Files/shop.php: -------------------------------------------------------------------------------- 1 | $_GET["id"], 21 | 'item_name' => $_POST["hidden_name"], 22 | 'product_price' => $_POST["hidden_price"], 23 | 'item_quantity' => $_POST["quantity"] 24 | ); 25 | $_SESSION["cart"][$count] = $item_array; 26 | echo ''; 27 | echo ''; 28 | 29 | } 30 | 31 | //if item already added to cart. Show Error. 32 | else 33 | { 34 | echo ''; 35 | echo ''; 36 | } 37 | } 38 | 39 | //if cart is empty. Create SESSION["cart"] 40 | else 41 | { 42 | $item_array = array( 43 | 'product_id' => $_GET["id"], 44 | 'item_name' => $_POST["hidden_name"], 45 | 'product_price' => $_POST["hidden_price"], 46 | 'item_quantity' => $_POST["quantity"] 47 | ); 48 | $_SESSION["cart"][0] = $item_array; 49 | echo ''; 50 | echo ''; 51 | } 52 | } 53 | 54 | //If user click delete item. Unset SESSION["cart"] to empty the card. 55 | if(isset($_GET["action"])) 56 | { 57 | if($_GET["action"] == "delete") 58 | { 59 | foreach($_SESSION["cart"] as $keys => $values) 60 | { 61 | if($values["product_id"] == $_GET["id"]) 62 | { 63 | unset($_SESSION["cart"][$keys]); 64 | echo ''; 65 | echo ''; 66 | } 67 | } 68 | } 69 | } 70 | ?> -------------------------------------------------------------------------------- /PHP Files/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: rgb(252, 252, 252); 3 | font-family: helvetica, arial, serif; 4 | font-size: 18px; 5 | text-align: center; 6 | } 7 | 8 | .wrap { 9 | display: inline-block; 10 | -webkit-box-shadow: 0 0 70px #fff; 11 | -moz-box-shadow: 0 0 70px #fff; 12 | box-shadow: 0 0 70px #fff; 13 | margin-top: 40px; 14 | } 15 | 16 | /* a little "umph" */ 17 | .decor { 18 | background: #6EAF8D; 19 | background: -webkit-linear-gradient(left, #CDEBDB 50%, #6EAF8D 50%); 20 | background: -moz-linear-gradient(left, #CDEBDB 50%, #6EAF8D 50%); 21 | background: -o-linear-gradient(left, #CDEBDB 50%, #6EAF8D 50%); 22 | background: linear-gradient(left, white 50%, #6EAF8D 50%); 23 | background-size: 50px 25%;; 24 | padding: 2px; 25 | display: block; 26 | } 27 | 28 | a { 29 | text-decoration: none; 30 | color: #fff; 31 | display: block; 32 | } 33 | 34 | ul { 35 | list-style: none; 36 | position: relative; 37 | text-align: left; 38 | } 39 | 40 | li { 41 | float: left; 42 | } 43 | 44 | /* clear'n floats */ 45 | ul:after { 46 | clear: both; 47 | } 48 | 49 | ul:before, 50 | ul:after { 51 | content: " "; 52 | display: table; 53 | } 54 | 55 | nav { 56 | position: relative; 57 | background: #2B2B2B; 58 | background-image: -webkit-linear-gradient(bottom, #2B2B2B 7%, #333333 100%); 59 | background-image: -moz-linear-gradient(bottom, #2B2B2B 7%, #333333 100%); 60 | background-image: -o-linear-gradient(bottom, #2B2B2B 7%, #333333 100%); 61 | background-image: linear-gradient(bottom, #2B2B2B 7%, #333333 100%); 62 | text-align: center; 63 | letter-spacing: 1px; 64 | text-shadow: 1px 1px 1px #0E0E0E; 65 | -webkit-box-shadow: 2px 2px 3px #888; 66 | -moz-box-shadow: 2px 2px 3px #888; 67 | box-shadow: 2px 2px 3px #888; 68 | border-bottom-right-radius: 8px; 69 | border-bottom-left-radius: 8px; 70 | } 71 | 72 | /* prime */ 73 | ul.primary li a { 74 | display: block; 75 | padding: 20px 30px; 76 | border-right: 1px solid #3D3D3D; 77 | } 78 | 79 | ul.primary li:last-child a { 80 | border-right: none; 81 | } 82 | 83 | ul.primary li a:hover { 84 | 85 | color: #000; 86 | } 87 | 88 | /* subs */ 89 | ul.sub { 90 | position: absolute; 91 | z-index: 200; 92 | box-shadow: 2px 2px 0 #BEBEBE; 93 | width: 35%; 94 | display:none; 95 | } 96 | 97 | ul.sub li { 98 | float: none; 99 | margin: 0; 100 | } 101 | 102 | ul.sub li a { 103 | border-bottom: 1px dotted #ccc; 104 | border-right: none; 105 | color: #000; 106 | padding: 15px 30px; 107 | } 108 | 109 | ul.sub li:last-child a { 110 | border-bottom: none; 111 | } 112 | 113 | ul.sub li a:hover { 114 | color: #000; 115 | background: #eeeeee; 116 | } 117 | 118 | /* sub display*/ 119 | ul.primary li:hover ul { 120 | display: block; 121 | background: #fff; 122 | } 123 | 124 | /* keeps the tab background white */ 125 | ul.primary li:hover a { 126 | background: #fff; 127 | color: #666; 128 | text-shadow: none; 129 | } 130 | 131 | ul.primary li:hover > a{ 132 | color: #000; 133 | } 134 | 135 | @media only screen and (max-width: 600px) { 136 | .decor { 137 | padding: 3px; 138 | } 139 | 140 | .wrap { 141 | width: 100%; 142 | margin-top: 0px; 143 | } 144 | 145 | li { 146 | float: none; 147 | } 148 | 149 | ul.primary li:hover a { 150 | background: none; 151 | color: #8B8B8B; 152 | text-shadow: 1px 1px #000; 153 | } 154 | 155 | ul.primary li:hover ul { 156 | display: block; 157 | background: #272727; 158 | color: #fff; 159 | } 160 | 161 | ul.sub { 162 | display: block; 163 | position: static; 164 | box-shadow: none; 165 | width: 100%; 166 | } 167 | 168 | ul.sub li a { 169 | background: #272727; 170 | border: none; 171 | color: #8B8B8B; 172 | } 173 | 174 | ul.sub li a:hover { 175 | color: #ccc; 176 | background: none; 177 | } 178 | } -------------------------------------------------------------------------------- /PHP Files/success.php: -------------------------------------------------------------------------------- 1 | query("SELECT * FROM Customers WHERE customerID=".$_SESSION['userSession']); 15 | $userRow=$query->fetch_array(); 16 | $DBcon->close(); 17 | 18 | ?> 19 | 20 | 21 | 22 | 23 | 24 |

Congratulation! You are logged in.

25 | 26 | 27 | 28 | 29 |
  •  Hi  
  • 30 |
  •  Log Out
  • 31 | 32 | 33 | 34 |

    You can check out now. Click here to check out your order.

    35 | 36 | -------------------------------------------------------------------------------- /PHP Files/yourcart.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

    Your shopping cart

    14 |
    15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | $values) 31 | { 32 | ?> 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 46 |
    Product NameQuantityPrice DetailsOrder TotalDelete
    $ $ "> X
    47 |
    48 |
    49 |
    50 |

    Sub total: $

    51 |

    Tax: $

    52 |

    Total: $

    53 |

    Click here to check out

    54 |
    55 |
    56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PHP-MySQL-Shopping-Website 2 | This is a website written in PHP & MySQL that works similarly like Amazon and other popular shopping website. It has a relational database for users and products. The users will have the ability to search for items, add-to-cart, review-cart and check out. 3 | --------------------------------------------------------------------------------