-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsert.php
More file actions
76 lines (61 loc) · 1.95 KB
/
insert.php
File metadata and controls
76 lines (61 loc) · 1.95 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
67
68
69
70
71
72
73
74
75
<!DOCTYPE html>
<html>
<head>
<title>search engine</title>
</head>
<body bgcolor="grey">
<form action="insert.php" method="post" enctype="multipart/form-data">
<table bgcolor="orange" width="500" border="2" cellspacing="2" align="center">
<tr>
<td colspan="5"><h2>Inserting new website:</h2></td>
</tr>
<tr>
<td>site title:</td>
<td><input type="text" name="site_title"></td>
</tr>
<tr>
<td>site link:</td>
<td><input type="text" name="site_link"></td>
</tr>
<tr>
<td>site keywords:</td>
<td><input type="text" name="site_keywords"></td>
</tr>
<tr>
<td>site description:</td>
<td><textarea cols="18" rows="8" name="site_desc"></textarea></td>
</tr>
<tr>
<td>site image:</td>
<td><input type="file" name="site_image"></td>
</tr>
<tr>
<td colspan="5"><input type="submit" name="submit" value="Add site now"></td>
</tr>
</table>
</form>
</body>
</html>
<?php
$con=mysqli_connect("localhost","root","","search");
mysqli_select_db($con,"search");
if(isset($_POST['submit'])){
$site_title = $_POST['site_title'];
$site_link = $_POST['site_link'];
$site_keywords = $_POST['site_keywords'];
$site_desc = $_POST['site_desc'];
$site_image = $_FILES['site_image']['name'];
$site_image_tmp = $_FILES['site_image']['tmp_name'];
if($site_title==" " OR $site_link==" " OR $site_keywords==" " OR $site_desc==" "){
echo "<script>alert('please fill all the fields')</script>";
exit();
}
else{
$insert_query = "insert into sites (site_title,site_link,site_keywords,site_desc,site_image) values('$site_title','$site_link','$site_keywords','$site_desc','$site_image')";
move_uploaded_file($site_image_tmp,"images/{$site_image}");
if(mysqli_query($con,$insert_query)){
echo "<script>alert('data inserted in to table')</script>";
}
}
}
?>