-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsignup-submit.php
More file actions
53 lines (47 loc) · 1.58 KB
/
Copy pathsignup-submit.php
File metadata and controls
53 lines (47 loc) · 1.58 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
<?php
include_once 'includes/db.php';
if (isset($_POST['submit'])) {
$fname = mysqli_real_escape_string($con, $_POST['fname']);
$lname = mysqli_real_escape_string($con, $_POST['lname']);
$name = $fname . " " . $lname;
$email = mysqli_real_escape_string($con, $_POST['email']);
$phone = mysqli_real_escape_string($con, $_POST['phno']);
$password = md5(mysqli_real_escape_string($con, $_POST['pass']));
$sql = "SELECT email FROM users WHERE email='$email'";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) == 0) {
$query = "INSERT INTO users (name,email,phone,password) VALUES (?, ?, ?, ?)";
$stmt = mysqli_prepare($con, $query);
mysqli_stmt_bind_param($stmt, "ssss", $name, $email, $phone, $password);
mysqli_stmt_execute($stmt);
$affected_rows = mysqli_stmt_affected_rows($stmt);
if ($affected_rows == 1) {
?>
<script>
alert("You have successfully signed up !");
location.href = "list.php";
</script>
<?php
mysqli_stmt_close($stmt);
mysqli_close($con);
} else {
?>
<script>
alert("An error occurred. Try again later !");
location.href = "index.php";
</script>
<?php
echo mysqli_error($con);
mysqli_stmt_close($stmt);
mysqli_close($con);
}
} else {
?>
<script>
alert("User already exists");
location.href = "signup.php";
</script>
<?php
}
}
?>