-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadmin_home.php
More file actions
66 lines (56 loc) · 2.15 KB
/
Copy pathadmin_home.php
File metadata and controls
66 lines (56 loc) · 2.15 KB
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
<?php
include("config.php");
session_start();
$sql = "SELECT * FROM login";
$result = mysqli_query($db,$sql) or die( mysqli_error($db));
$count = mysqli_num_rows($result);
if(isset($_POST['but_upload'])){
$pname=$_POST['pname'];
$price=$_POST['price'];
$name = $_FILES['file']['name'];
$target_dir = "images/products/";
$target_file = $target_dir . basename($_FILES["file"]["name"]);
// Select file type
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Valid file extensions
$extensions_arr = array("jpg","jpeg","png","gif");
// Check extension
if( in_array($imageFileType,$extensions_arr) ){
// Insert record
$query = "insert into product(`ID`, `pname`, `price`,`image`) values(NULL,'$pname','$price','".$name."')";
mysqli_query($db,$query);
// Upload file
move_uploaded_file($_FILES['file']['tmp_name'],$target_dir.$name);
}
}
?>
<html>
<head>
<title>Admin Home</title>
</head>
<body>
<table>
<tr>
<th>ID</th>
<td>User Name</td>
<td>Password</td>
</tr>
<?php
while($rows=mysqli_fetch_array($result)){
?>
<tr>
<td><?php echo $rows['ID'] ?></td>
<td><?php echo $rows['username'] ?></td>
<td><?php echo $rows['password'] ?></td>
</tr>
<?php }?>
</table>
<h1> Product Entry: </h1>
<form method="post" action="" enctype='multipart/form-data'>
<input type='text' name='pname' placeholder='Enter Product Name'/>
<input type='Number' name='price' placeholder='Enter Price'/>
<input type='file' name='file' />
<input type='submit' value='Save Product' name='but_upload'>
</form>
</body>
</html>