-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathIdeaSubmit.php
195 lines (149 loc) · 4.8 KB
/
IdeaSubmit.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?php
ob_start();
?>
<?php
require "ulogged.php";
require "footer.html";
require "includes/udbh.inc.php";
require "uheader.php";
?>
<html>
<head>
<title>Register Page</title>
<style type="text/css">
input[type=text],select,input[type=email],input[type=tel],textarea,input[type=date], input[type=password] {
width: 30%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid black;
box-sizing: border-box;}
button {
background-color:black;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
cursor: pointer;
width: 20%;
}
button:hover {
background-color:green;
}
</style>
</head>
<body>
<main>
<div align="center" >
<form id="saiko" action="IdeaSubmit.php" method="post" enctype = "multipart/form-data">
<label for=""><b>title of idea:</b></label>
<input type="text" name="title" id="fid" placeholder="write a suitable title"><br>
<label for="mail"><b>Email id:</b></label>
<input type="email" name="mail" placeholder="someone@something.com"><br>
<label for="category"><b>category:</b></label>
<select class="select" name="category">
<option value="software">Software</option>
<option value="hardware">Hardware</option>
<option value="other">Other</option>
</select><br>
<label for="field"><b>Field:</b></label>
<select class="select" name="field">
<option value="agriculture">Agriculture</option>
<option value="sensors">Sensors</option>
<option value="space">Space</option>
<option value="robotics">Robotics</option>
<option value="other">Other</option>
</select><br>
<label for="mobnum"><b>Mobile number:</b></label>
<input type="tel" name="mobnum" maxlength="10" placeholder="mobilenumber"></input><br>
<label for="desc"><b>Description:</b></label>
<textarea name="desc" rows="10" column="20" size="10px" placeholder="descibe your idea<br>in 500 words"></textarea><br>
<label for="file">Reference docs</label>
<input type="file" name="image">
<br><button type="submit" name="idea-submit">Submit Idea</button>
</form></div>
</main>
</body>
</html>
<?php
if(isset($_POST['idea-submit'])){
$title=$_POST['title'];
$email=$_POST['mail'];
$category=$_POST['category'];
$field=$_POST['field'];
$mobile=$_POST['mobnum'];
$description=$_POST['desc'];
$getDetails="SELECT FirstName,LastName,ADDRESS FROM `personaldetail` WHERE username='$user'";
$sqlrun=mysqli_query($conn,$getDetails);
if ($sqlrun->num_rows > 0) {
// output data of each row
while($row = $sqlrun->fetch_assoc()) {
$Firstname=$row["FirstName"];
$Lastname=$row["LastName"];
$address=$row["ADDRESS"];
}
echo $user ;
echo $Firstname ;
echo $Lastname.$address ;
} else {
exit();
}
//empty validation
if(empty($title) || empty($email) ||
empty($category) || empty($field) || empty($mobile) || empty($description) || empty($address)){
echo '<script language="javascript">';
echo 'alert("Please Fill all the fields")'; //not showing an alert box.
echo '</script>';
exit();
}
//mobile validations
else if(!preg_match("/^[0-9]*$/", $mobile)){
echo '<script language="javascript">';
echo 'alert("enter valid mobile.No")';
echo '</script>';
exit();
}
else if(strlen($mobile)!=10){
echo '<script language="javascript">';
echo 'alert("enter valid mobile.No")';
echo '</script>';
exit();
}
//TAKING IMAGE
else{
if(isset($_FILES['image'])){
$errors= array();
$file_name = $_FILES['image']['name'];
$file_size = $_FILES['image']['size'];
$file_tmp = $_FILES['image']['tmp_name'];
$file_type = $_FILES['image']['type'];
$file_ext=strtolower(end(explode('.',$_FILES['image']['name'])));
$extensions= array("jpeg","jpg","png");
if(in_array($file_ext,$extensions)=== false){
$errors[]="extension not allowed, please choose a JPEG or PNG file.";
}
if($file_size > 2097152) {
$errors[]='File size must be excately 2 MB';
}
if(empty($errors)==true) {
move_uploaded_file($file_tmp,"images/$user-$title".$file_name);
}else{
print_r($errors);
echo '<script language="javascript">';
echo 'alert("Please insert the image")';
echo '</script>';
exit();
}
}
$location="images/$user-$title$file_name";
$submitDetails="insert into `ideas`(username ,name,title,email,category,field,MobileNo,description,Address,Filelocation)
values ('$user','$Firstname $Lastname','$title','$email','$category','$field',$mobile,'$description','$address','$location')";
mysqli_query($conn,$submitDetails);
mysqli_close($conn);
echo '<script language="javascript">';
echo 'alert("Sucessfully Submitted")';
echo '</script>';
}
exit();
}
?>