Add files via upload
This commit is contained in:
parent
2f67e0fe4a
commit
125568e992
8 changed files with 1111 additions and 0 deletions
44
register_login.php
Normal file
44
register_login.php
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
function checkAndRegister() {
|
||||
$conn = mysqli_connect("localhost", "root", "", "speedtest");
|
||||
$query = "SELECT `email` FROM `users` WHERE email='".$_POST["email"]."' AND username='".$_POST["username"]."' AND password='".$_POST["password"]."'";
|
||||
$count = mysqli_num_rows(mysqli_query($conn, $query));
|
||||
|
||||
//checking if user already exits, then send back;
|
||||
if($count > 0) {
|
||||
mysqli_close($conn);
|
||||
echo "<script>alert('user already exits. Please login instead')</script>";
|
||||
echo "<script>history.back()</script>";
|
||||
} else {
|
||||
$query = "INSERT INTO `users` (`username`, `password`, `email`) VALUES ('".$_POST["username"]."', '".$_POST["password"]."', '".$_POST["email"]."')";
|
||||
mysqli_query($conn, $query);
|
||||
$query = "SELECT `id` FROM `users` WHERE email='".$_POST["email"]."' AND username='".$_POST["username"]."' AND password='".$_POST["password"]."'";
|
||||
$query = mysqli_fetch_array(mysqli_query($conn, $query))['id'];
|
||||
mysqli_close($conn);
|
||||
echo "<script>window.location.replace('./main.php?id=".$query."');</script>";
|
||||
}
|
||||
}
|
||||
|
||||
function checkAndLogin() {
|
||||
$conn = mysqli_connect("localhost", "root", "", "speedtest");
|
||||
$query = "SELECT `email` FROM `users` WHERE email='".$_POST["email"]."' AND username='".$_POST["username"]."' AND password='".$_POST["password"]."'";
|
||||
$count = mysqli_num_rows(mysqli_query($conn, $query));
|
||||
|
||||
if($count == 0) {
|
||||
mysqli_close($conn);
|
||||
echo "<script>alert('Wrong Credentials!!')</script>";
|
||||
echo "<script>history.back()</script>";
|
||||
} else {
|
||||
$query = "SELECT `id` FROM `users` WHERE email='".$_POST["email"]."' AND username='".$_POST["username"]."' AND password='".$_POST["password"]."'";
|
||||
$query = mysqli_fetch_array(mysqli_query($conn, $query))["id"];
|
||||
mysqli_close($conn);
|
||||
echo "<script>window.location.replace('./main.php?id=".$query."');</script>";
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($_POST['register'])) {
|
||||
checkAndRegister();
|
||||
} else if(isset($_POST['sign-in'])) {
|
||||
checkAndLogin();
|
||||
}
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue