-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
70 lines (66 loc) · 1.9 KB
/
index.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
<html>
<head>
<title>Add Item</title>
</head>
<body>
<?php include 'dbz.php'; ?>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$type = format_input($_POST["type"]);
$title = format_input($_POST["title"]);
$description = format_input($_POST["description"]);
$name = format_input($_POST["name"]);
$phone = format_input($_POST["phone"]);
$email = format_input($_POST["email"]);
$image = base64_encode(file_get_contents($_FILES['image']['tmp_name']));
// save in db
mysqli_query($connect, "INSERT INTO item(type, title, description, name, phone, email, image)
VALUES('$type', '$title', '$description', '$name', '$phone', '$email','$image')");
}
function format_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<h2>New Item</h2>
<form method="post" action="<?= $_SERVER['PHP_SELF'] ?>" enctype="multipart/form-data">
<table>
<tr>
<td>Type:</td>
<td><input type="text" name="type"></td>
</tr>
<tr>
<td>Title:</td>
<td><input type="text" name="title"></td>
</tr>
<tr>
<td>Description:</td>
<td><textarea name="description" rows="5" cols="40"></textarea></td>
</tr>
<tr>
<td>Image(browse):</td>
<td><input type="file" name="image"/></td>
</tr>
<tr>
<td>Name:</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td>Phone:</td>
<td><input type="text" name="phone"></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="email"></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Submit"></td>
</tr>
</table>
</form>
<a href="view.php">view</a>
</body>
</html>