-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-product.php
106 lines (92 loc) · 4.16 KB
/
add-product.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
include 'protect.php';
if ( isset($_REQUEST["title"]) )
{
//Get our form data
$title = $_REQUEST["title"]; //$_GET $_POST
$description = $_REQUEST["description"];
$price = $_REQUEST["price"];
$genre = $_REQUEST["genre"];
$target_dir = "uploads/";//kenya.png ==>676767688kenya.png
$target_file = $target_dir .rand(1000000,10000000). basename($_FILES["poster"]["name"]);
$imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));
$allowed_types = ["png", "jpeg", "jpg", "gif"];
$allowed = in_array($imageFileType, $allowed_types);
if ($allowed and move_uploaded_file($_FILES["poster"]["tmp_name"], $target_file)) {
// echo "Uploaded";
$status = 1;
} else {
//echo "Failed";
$status = 2;
}
require_once 'connect.php';
//$sql = "INSERT INTO `products`(`id`, `title`, `poster`, `description`, `genre`, `price`)
// VALUES (null,'$title','$target_file','$description','$genre','$price')";
//mysqli_query($con, $sql) or die( mysqli_error($con) );// executing the query
$stmt = mysqli_prepare($con , "INSERT INTO `products`( `title`, `poster`, `description`, `genre`, `price`)
VALUES (?,?,?,?,?)");
//bind data
mysqli_stmt_bind_param($stmt, "sssss", $title, $target_file, $description, $genre, $price);
mysqli_stmt_execute($stmt);
mysqli_close($con);//close the connection
setcookie("success", "Product Added", time()+3);
header("location: add-product.php");
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>New Product</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<?php include 'nav.php' ?>
<div class="container">
<div class="row justify-content-center">
<div class="col-sm-5">
<?php include 'alert.php' ?>
<h4>New Product</h4>
<form action="add-product.php" method="post" enctype="multipart/form-data">
<div class="form-group">
<label>Title</label>
<input type="text" class="form-control" name="title" required>
</div>
<div class="form-group">
<label>Poster</label>
<input type="file" accept="image/*" max-size="2824" class="form-control-file border" name="poster" required>
</div>
<div class="form-group">
<label>Description</label>
<textarea name="description" class="form-control"></textarea>
</div>
<label>Genre</label>
<select name="genre" class="form-control">
<option value="Thriller">Thriller Movie</option>
<option value="Documentary">Documentary Movie</option>
<option value="Horror">Horror Movie</option>
<option value="Action">Action Movie</option>
<option value="Romance">Romance Movie</option>
<option value="Superhero">Superhero Movie</option>
<option value="Comedy">Comedy Movie</option>
<option value="Bollywood">Bollywood Movie</option>
<option value="Nollywood">Nollywood Movie</option>
<option value="Riverwood">Riverwood Movie</option>
</select>
<div class="form-group">
<label>Price</label>
<input type="number" class="form-control" name="price" required>
</div>
<button class="btn btn-danger">Submit</button>
</form>
</div>
</div>
</div>
</body>
</html>