Skip to content

Commit d8275e7

Browse files
committed
Initial source code checkin.
1 parent 95d2a44 commit d8275e7

File tree

91 files changed

+25850
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+25850
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# complete-php7-ecom-website
2-
A complete PHP 7 eCommerce website along with Admin interface.
2+
3+
An advanced and complete PHP 7 eCommerce website along with MySQL database and Admin interface.

addtocart.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
session_start();
3+
if (isset($_GET) & !empty($_GET)) {
4+
$id = $_GET['id'];
5+
if (isset($_GET['quant']) & !empty($_GET['quant'])) {
6+
$quant = $_GET['quant'];
7+
} else {
8+
$quant = 1;
9+
}
10+
$_SESSION['cart'][$id] = array("quantity" => $quant);
11+
header('location: cart.php');
12+
} else {
13+
header('location: cart.php');
14+
}
15+
echo "<pre>";
16+
print_r($_SESSION['cart']);
17+
echo "</pre>";

addtowishlist.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
ob_start();
3+
session_start();
4+
require_once 'config/connect.php';
5+
$uid = $_SESSION['customerid'];
6+
if (!isset($_SESSION['customer']) & empty($_SESSION['customer'])) {
7+
header('location: login.php');
8+
}
9+
if (isset($_GET['id']) & !empty($_GET['id'])) {
10+
$pid = $_GET['id'];
11+
echo $sql = "INSERT INTO wishlist (pid, uid) VALUES ($pid, $uid)";
12+
$res = mysqli_query($connection, $sql);
13+
if ($res) {
14+
header('location: wishlist.php');
15+
//echo "redirect to wish list page";
16+
}
17+
} else {
18+
header('location: wishlist.php');
19+
}

admin/addcategory.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
session_start();
3+
require_once '../config/connect.php';
4+
if (!isset($_SESSION['email']) & empty($_SESSION['email'])) {
5+
header('location: login.php');
6+
}
7+
8+
if (isset($_POST) & !empty($_POST)) {
9+
$name = mysqli_real_escape_string($connection, $_POST['categoryname']);
10+
$sql = "INSERT INTO category (name) VALUES ('$name')";
11+
$res = mysqli_query($connection, $sql);
12+
if ($res) {
13+
$smsg = "Category Added";
14+
} else {
15+
$fmsg = "Failed Add Category";
16+
}
17+
}
18+
?>
19+
<?php include 'inc/header.php'; ?>
20+
<?php include 'inc/nav.php'; ?>
21+
22+
<section id="content">
23+
<div class="content-blog">
24+
<div class="container">
25+
<?php if (isset($fmsg)) { ?>
26+
<div class="alert alert-danger" role="alert"><?php echo $fmsg; ?></div>
27+
<?php } ?>
28+
<?php if (isset($smsg)) { ?>
29+
<div class="alert alert-success" role="alert"> <?php echo $smsg; ?> </div>
30+
<?php } ?>
31+
<form method="post">
32+
<div class="form-group">
33+
<label for="Productname">Category Name</label>
34+
<input type="text" class="form-control" name="categoryname" id="Categoryname" placeholder="Category Name">
35+
</div>
36+
<button type="submit" class="btn btn-default">Submit</button>
37+
</form>
38+
39+
</div>
40+
</div>
41+
</section>
42+
43+
<?php include 'inc/footer.php' ?>

admin/addproduct.php

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<?php
2+
session_start();
3+
require_once '../config/connect.php';
4+
if (!isset($_SESSION['email']) & empty($_SESSION['email'])) {
5+
header('location: login.php');
6+
}
7+
8+
if (isset($_POST) & !empty($_POST)) {
9+
$prodname = mysqli_real_escape_string($connection, $_POST['productname']);
10+
$description = mysqli_real_escape_string($connection, $_POST['productdescription']);
11+
$category = mysqli_real_escape_string($connection, $_POST['productcategory']);
12+
$price = mysqli_real_escape_string($connection, $_POST['productprice']);
13+
14+
15+
if (isset($_FILES) & !empty($_FILES)) {
16+
$name = $_FILES['productimage']['name'];
17+
$size = $_FILES['productimage']['size'];
18+
$type = $_FILES['productimage']['type'];
19+
$tmp_name = $_FILES['productimage']['tmp_name'];
20+
21+
$max_size = 10000000;
22+
$extension = substr($name, strpos($name, '.') + 1);
23+
24+
if (isset($name) && !empty($name)) {
25+
if (($extension == "jpg" || $extension == "jpeg") && $type == "image/jpeg" && $size<=$max_size) {
26+
$location = "uploads/";
27+
if (move_uploaded_file($tmp_name, $location.$name)) {
28+
//$smsg = "Uploaded Successfully";
29+
$sql = "INSERT INTO products (name, description, catid, price, thumb) VALUES ('$prodname', '$description', '$category', '$price', '$location$name')";
30+
$res = mysqli_query($connection, $sql);
31+
if ($res) {
32+
//echo "Product Created";
33+
header('location: products.php');
34+
} else {
35+
$fmsg = "Failed to Create Product";
36+
}
37+
} else {
38+
$fmsg = "Failed to Upload File";
39+
}
40+
} else {
41+
$fmsg = "Only JPG files are allowed and should be less that 1MB";
42+
}
43+
} else {
44+
$fmsg = "Please Select a File";
45+
}
46+
} else {
47+
$sql = "INSERT INTO products (name, description, catid, price) VALUES ('$prodname', '$description', '$category', '$price')";
48+
$res = mysqli_query($connection, $sql);
49+
if ($res) {
50+
header('location: products.php');
51+
} else {
52+
$fmsg = "Failed to Create Product";
53+
}
54+
}
55+
}
56+
?>
57+
<?php include 'inc/header.php'; ?>
58+
<?php include 'inc/nav.php'; ?>
59+
60+
<section id="content">
61+
<div class="content-blog">
62+
<div class="container">
63+
<?php if (isset($fmsg)) {
64+
?><div class="alert alert-danger" role="alert"> <?php echo $fmsg; ?> </div><?php
65+
} ?>
66+
<?php if (isset($smsg)) {
67+
?><div class="alert alert-success" role="alert"> <?php echo $smsg; ?> </div><?php
68+
} ?>
69+
<form method="post" enctype="multipart/form-data">
70+
<div class="form-group">
71+
<label for="Productname">Product Name</label>
72+
<input type="text" class="form-control" name="productname" id="Productname" placeholder="Product Name">
73+
</div>
74+
<div class="form-group">
75+
<label for="productdescription">Product Description</label>
76+
<textarea class="form-control" name="productdescription" rows="3"></textarea>
77+
</div>
78+
79+
<div class="form-group">
80+
<label for="productcategory">Product Category</label>
81+
<select class="form-control" id="productcategory" name="productcategory">
82+
<option value="">---SELECT CATEGORY---</option>
83+
<?php
84+
$sql = "SELECT * FROM category";
85+
$res = mysqli_query($connection, $sql);
86+
while ($r = mysqli_fetch_assoc($res)) {
87+
?>
88+
<option value="<?php echo $r['id']; ?>"><?php echo $r['name']; ?></option>
89+
<?php
90+
} ?>
91+
</select>
92+
</div>
93+
94+
<div class="form-group">
95+
<label for="productprice">Product Price</label>
96+
<input type="text" class="form-control" name="productprice" id="productprice" placeholder="Product Price">
97+
</div>
98+
<div class="form-group">
99+
<label for="productimage">Product Image</label>
100+
<input type="file" name="productimage" id="productimage">
101+
<p class="help-block">Only jpg/png are allowed.</p>
102+
</div>
103+
104+
<button type="submit" class="btn btn-default">Submit</button>
105+
</form>
106+
107+
</div>
108+
</div>
109+
</section>
110+
111+
<?php include 'inc/footer.php' ?>

admin/categories.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
session_start();
3+
require_once '../config/connect.php';
4+
if (!isset($_SESSION['email']) & empty($_SESSION['email'])) {
5+
header('location: login.php');
6+
}
7+
?>
8+
<?php include 'inc/header.php'; ?>
9+
<?php include 'inc/nav.php'; ?>
10+
11+
<section id="content">
12+
<div class="content-blog">
13+
<div class="container">
14+
<table class="table table-striped">
15+
<thead>
16+
<tr>
17+
<th>#</th>
18+
<th>Category Name</th>
19+
<th>Operations</th>
20+
</tr>
21+
</thead>
22+
<tbody>
23+
<?php
24+
$sql = "SELECT * FROM category";
25+
$res = mysqli_query($connection, $sql);
26+
while ($r = mysqli_fetch_assoc($res)) {
27+
?>
28+
<tr>
29+
<th scope="row"><?php echo $r['id']; ?></th>
30+
<td><?php echo $r['name']; ?></td>
31+
<td><a href="editcategory.php?id=<?php echo $r['id']; ?>">Edit</a> | <a href="delcategory.php?id=<?php echo $r['id']; ?>">Delete</a></td>
32+
</tr>
33+
<?php
34+
} ?>
35+
</tbody>
36+
</table>
37+
38+
</div>
39+
</div>
40+
</section>
41+
42+
<?php include 'inc/footer.php' ?>

admin/customers.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
session_start();
3+
require_once '../config/connect.php';
4+
if (!isset($_SESSION['email']) & empty($_SESSION['email'])) {
5+
header('location: login.php');
6+
}
7+
?>
8+
<?php include 'inc/header.php'; ?>
9+
<?php include 'inc/nav.php'; ?>
10+
11+
<section id="content">
12+
<div class="content-blog">
13+
<div class="container">
14+
<table class="table table-striped">
15+
<thead>
16+
<tr>
17+
<th>#</th>
18+
<th>Customer Name</th>
19+
<th>Customer Mobile</th>
20+
<th>Customer Email</th>
21+
<th>Customer From</th>
22+
</tr>
23+
</thead>
24+
<tbody>
25+
<?php
26+
$sql = "SELECT * FROM users u JOIN usersmeta u1 WHERE u.id=u1.uid";
27+
$res = mysqli_query($connection, $sql);
28+
while ($r = mysqli_fetch_assoc($res)) {
29+
?>
30+
<tr>
31+
<th scope="row"><?php echo $r['id']; ?></th>
32+
<td><?php echo $r['firstname'] . " " . $r['lastname']; ?></td>
33+
<td><?php echo $r['mobile']; ?></td>
34+
<td><?php echo $r['email']; ?></td>
35+
<td><?php echo $r['timestamp']; ?></td>
36+
37+
<?php
38+
} ?>
39+
</tbody>
40+
</table>
41+
</div>
42+
</div>
43+
</section>
44+
45+
<?php include 'inc/footer.php' ?>

admin/delcategory.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
session_start();
3+
require_once '../config/connect.php';
4+
if (!isset($_SESSION['email']) & empty($_SESSION['email'])) {
5+
header('location: login.php');
6+
}
7+
8+
if (isset($_GET) & !empty($_GET)) {
9+
$id = $_GET['id'];
10+
$sql = "DELETE FROM category WHERE id='$id'";
11+
if (mysqli_query($connection, $sql)) {
12+
header('location:categories.php');
13+
}
14+
} else {
15+
header('location: categories.php');
16+
}

admin/delprodimg.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
session_start();
3+
require_once '../config/connect.php';
4+
if (!isset($_SESSION['email']) & empty($_SESSION['email'])) {
5+
header('location: login.php');
6+
}
7+
8+
if (isset($_GET['id']) & !empty($_GET['id'])) {
9+
$id = $_GET['id'];
10+
$sql = "SELECT thumb FROM products WHERE id=$id";
11+
$res = mysqli_query($connection, $sql);
12+
$r = mysqli_fetch_assoc($res);
13+
if (!empty($r['thumb'])) {
14+
if (unlink($r['thumb'])) {
15+
$delsql = "UPDATE products SET thumb='' WHERE id=$id";
16+
if (mysqli_query($connection, $delsql)) {
17+
header("location:editproduct.php?id={$id}");
18+
}
19+
} else {
20+
$delsql = "UPDATE products SET thumb='' WHERE id=$id";
21+
if (mysqli_query($connection, $delsql)) {
22+
header("location:editproduct.php?id={$id}");
23+
}
24+
}
25+
} else {
26+
$delsql = "UPDATE products SET thumb='' WHERE id=$id";
27+
if (mysqli_query($connection, $delsql)) {
28+
header("location:editproduct.php?id={$id}");
29+
}
30+
}
31+
} else {
32+
header("location:editproduct.php?id={$id}");
33+
}

admin/delproduct.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
session_start();
3+
require_once '../config/connect.php';
4+
if (!isset($_SESSION['email']) & empty($_SESSION['email'])) {
5+
header('location: login.php');
6+
}
7+
8+
if (isset($_GET['id']) & !empty($_GET['id'])) {
9+
$id = $_GET['id'];
10+
$sql = "SELECT thumb FROM products WHERE id=$id";
11+
$res = mysqli_query($connection, $sql);
12+
$r = mysqli_fetch_assoc($res);
13+
if (!empty($r['thumb'])) {
14+
if (unlink($r['thumb'])) {
15+
$delsql = "DELETE FROM products WHERE id=$id";
16+
if (mysqli_query($connection, $delsql)) {
17+
header("location:products.php");
18+
}
19+
}
20+
} else {
21+
$delsql = "DELETE FROM products WHERE id=$id";
22+
if (mysqli_query($connection, $delsql)) {
23+
header("location:products.php");
24+
}
25+
}
26+
} else {
27+
header('location: products.php');
28+
}

0 commit comments

Comments
 (0)