-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.php
executable file
·77 lines (68 loc) · 2.1 KB
/
register.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
<!--/*# ------------ changed to mysqli=------------------ -->
<!doctype html>
<html>
<head>
<title>Register</title>
<style>
body{
margin-top: 100px;
margin-bottom: 100px;
margin-right: 150px;
margin-left: 80px;
background-color: azure ;
color: palevioletred;
font-family: verdana;
font-size: 100%
}
h1 {
color: indigo;
font-family: verdana;
font-size: 100%;
}
h2 {
color: indigo;
font-family: verdana;
font-size: 100%;
}</style>
</head>
<body>
<center><h1>CREATE REGISTRATION AND LOGIN FORM USING PHP AND mysqli</h1></center>
<p><a href="register.php">Register</a> | <a href="login.php">Login</a></p>
<center><h2>Registration Form</h2></center>
<form action="" method="POST">
<legend>
<fieldset>
Username: <input type="text" name="user"><br />
Password: <input type="password" name="pass"><br /> <br>
<input type="submit" value="Register" name="submit" />
</fieldset>
</legend>
</form>
<?php
if(isset($_POST["submit"])){
if(!empty($_POST['user']) && !empty($_POST['pass'])) {
$user=$_POST['user'];
$pass=$_POST['pass'];
$con=mysqli_connect('localhost','root','') or die(mysqli_error());
mysqli_select_db($con,'alphacrm') or die(mysqli_error("Cant connect")); /*<!- mysqli_error($con)-> /*cannot select DB */
$query=mysqli_query($con,"SELECT * FROM login WHERE username='".$user."'");
$numrows=mysqli_num_rows($query);
if($numrows==0)
{
$sql="INSERT INTO login(username,password) VALUES('$user','$pass')";
$result=mysqli_query($con,$sql);
if($result){
echo "Account Successfully Created";
} else {
echo "Failure!";
}
} else {
echo "That username already exists! Please try again with another.";
}
} else {
echo "All fields are required!";
}
}
?>
</body>
</html>