-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddcrop.php
109 lines (100 loc) · 3.39 KB
/
addcrop.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
107
108
<?php
session_start();
include_once("conn.php");
if(isset($_FILES["cropimg"]["name"])){
$name = $_POST['txtname'];
$desc = $_POST['txtdesc'];
$imageName = $_FILES["cropimg"]["name"];
$imageSize = $_FILES["cropimg"]["size"];
$tmpName = $_FILES["cropimg"]["tmp_name"];
$validImageExtension = ['jpg', 'jpeg', 'png'];
$imageExtension = explode('.', $imageName);
$imageExtension = strtolower(end($imageExtension));
if ($imageSize > 1200000){
echo
"
<script>
alert('Image Size Is Too Large');
document.location.href = 'admincrop.php';
</script>
";
}
elseif(empty($name || $desc)){
echo
"
<script>
alert('Please fill out the field.');
document.location.href = 'admincrop.php';
</script>
";
}else{
$sql = "INSERT INTO `crop`(`crop_name`, `image`, `body`) VALUES ('$name', '$imageName','$desc')";
mysqli_query($conn, $sql);
move_uploaded_file($tmpName, 'assimg/' . $imageName);
echo
"
<script>
document.location.href = 'admincrop.php';
</script>
";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel = "icon" href ="img/agronomy.png" type = "image/x-icon">
<link rel="stylesheet" href="mainpage.css">
<title>AgriComm</title>
</head>
<body>
<?php include("apheader.php") ?>
<br>
<div class="wraper">
<div class="sidebar">
<ul>
<li><a href="admin.php">Posts</a></li>
<li><a href="admincrop.php">Crop List</a></li>
<li><a href="memberList.php">Member list</a></li>
</ul>
</div>
<div class="post_content">
<h2 style="text-align: center;">Add Crop Information</h2>
<hr>
<form action="" method="POST" name="frminsert" enctype="multipart/form-data">
<table style="margin-left: 30%;">
<tr>
<td ><label>Crop Name</label></td>
<td> : <input type="text" name="txtname" style="width:402px"></td>
</tr>
<tr>
<td><label>Description : </label><br></td>
<td> <textarea name="txtdesc" cols="40" rows="5"></textarea></td>
</tr>
<tr>
<td><label>Image</label></td>
<td> : <input type="file" name="cropimg" id="cropimg"></td>
</tr>
<tr>
<td></td>
<td>
<br>
<input type="submit" value="Add">
<button><a href="admincrop.php" style="color: black;"> Cancel </a></button>
</td>
</tr>
</table>
</form>
</div>
</div>
<script type="text/javascript">
document.getElementById("cropimg").onchange = function(){
document.getElementById("frminsert").submit();
};
</script>
<?php include("footer.php") ?>
</body>
</html>