-
Notifications
You must be signed in to change notification settings - Fork 3
/
signup.php
81 lines (72 loc) · 1.94 KB
/
signup.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
<html>
<head><title> Sign up</title></head>
<?php
// define variables and set to empty values
$user= "";
$password= "";
$email= "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$user = test_input($_POST["user"]);
$password = test_input($_POST["password"]);
$email = test_input($_POST["email"]);
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<head>
<link rel="stylesheet" type="text/css" href="cascadesignup.css">
</head>
<p class="texto">Sign Up</p>
<div class="Registro">
<form method="post" action="signup.php">
<span class="fontawesome-user"></span>
<input type="text" required placeholder="username" autocomplete="off" name="user">
<br>
<span class="fontawesome-envelope-alt"></span>
<input type="email" id="email" required placeholder="Email" autocomplete="off" name="email">
<br>
<span class="fontawesome-lock"></span><input type="password" name="password" id="password" required placeholder="Password" autocomplete="off" name="password">
<input type="submit" value="Sign Up" title="register">
</body>
<?php
$servername = "localhost";
$username = "root";
$pass = "";
$dbname = "getmehome";
// Create connection
$conn = new mysqli($servername, $username, $pass, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$check=mysqli_query($conn,"select * from user where username='$user';");
$checkrows=mysqli_num_rows($check);
$flag=0;
if($checkrows==0&&$user!="")
{
$sql = "INSERT INTO `user`(`username`, `password`, `email`) VALUES ('$user','$password','$email');";
$flag=1;
header('location:first.php');
}
else if($checkrows>0)
{
echo'<br>';
echo'<br>';
echo'<br>';
echo "<font size=5>Username exists";
}
if($flag==1)
{
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
$conn->close();
?>
</html>