-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformaction.php
59 lines (50 loc) · 1.51 KB
/
formaction.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
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<script language="javascript">
function sweet(){
swal("Registered successfully!", "Thanks you!", "success").then((value)=>{
if(value){
window.location.href = "index.html";
}
else{
window.location.href = "index.html";
}
});
}
function exist(){
swal("Email already found!", "Use new email","warning").then((value) =>{
if(value){
window.location.href = "form.html";
}
else{
window.location.href = "form.html";
}
})
}
</script>
<?php
define('CDN', 'https://unpkg.com/sweetalert/dist/sweetalert.min.js');
include 'conn.php';
if(isset($_POST['submit'])){
$fname = $_POST['uname'];
$email = $_POST['email'];
$years = $_POST['years'];
$rno = $_POST['rno'];
$dept = $_POST['dept'];
}
$sql = "SELECT email FROM registration WHERE email = '$email'";
$res = mysqli_query($conn,$sql);
if(mysqli_num_rows($res) > 0)
{
echo '<script>setTimeout(function(){ exist(); }, 0);</script>';
}
else {
$sql = "INSERT INTO registration (fname,email, years, rollno, dept) VALUES ('$fname','$email','$years','$rno','$dept')";
if (mysqli_query($conn, $sql)) {
echo '<script>setTimeout(function(){ sweet(); }, 0);</script>';
}
else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
}
mysqli_close($conn);
?>