Created
February 2, 2019 11:15
-
-
Save Chandra0505/0705602f9a113d05d4f2e651b68c47d0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$dbhost = "localhost"; | |
$dbuser = "root"; | |
$dbpass = ""; | |
$dbname = "login"; | |
$conn = new mysqli($dbhost,$dbuser,$dbpass,$dbname); | |
if($conn->connect_error){ | |
die("Could not connect to the database!" . $conn->connect_error); | |
} | |
else { | |
echo "Connected successfully"; | |
} | |
// $uname = check_input($_POST['uname']); | |
// $pass = check_input($_POST['pass']); | |
// $pass = sha1($pass); | |
//// echo "$uname"; | |
// echo "$pass"; | |
if(isset($_POST['action']) && $_POST['action'] == 'register'){ | |
$uname = check_input($_POST['uname']); | |
$email = check_input($_POST['email']); | |
$pass = check_input($_POST['pass']); | |
$cpass = check_input($_POST['cpass']); | |
$pass = sha1($pass); | |
$cpass = sha1($cpass); | |
$created = date('Y-m-d'); | |
if($pass!= $cpass){ | |
echo "Password did not matched!"; | |
exit(); | |
} | |
else{ | |
$sql = $conn -> prepare("SELECT * FROM users WHERE username=? OR email = ?"); | |
$sql -> bind_param('ss',$uname, $email); | |
$sql -> execute(); | |
$result = $sql -> get_result(); | |
$row=$result -> fetch_array(MYSQLI_ASSOC); | |
if ($result['username'] == $uname) { | |
echo "Username not availabe try different"; | |
} | |
elseif ($result['email']==$email) { | |
echo "email is already taken diiferent"; | |
} | |
else { | |
$stmt = $conn -> prepare("INSERT INTO users (username, email, pass, created) VALUES (?, ?, ?, ?)"); | |
$stmt -> bind_param('ssss', $username, $email, $pass, $created); | |
if ($stmt->execute()) { | |
echo "Registrated sucessfully. Login Now!"; | |
$stmt->close(); | |
$conn->close(); | |
} | |
else { | |
echo "Something went wrong. Please try again"; | |
} | |
} | |
} | |
} | |
function check_input($data){ | |
$data = trim($data); | |
$data = stripslashes($data); | |
$data = htmlspecialchars($data); | |
return $data; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment