Last active
July 23, 2020 06:46
-
-
Save kabeer11000/61cbadcb6c37dc0951452f4dd8f6e613 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
//Javascript ki zaroorat nahi yeh sirf php code use karay ga | |
$server = "localhost"; | |
$user = "root"; | |
$password = ""; | |
$db = "userregistration"; | |
try { | |
$con = mysqli_connect($server, $user, $password, $db ); | |
}catch(Exception $e) { | |
echo 'Error Occured: ' .$e->getMessage(); | |
} | |
?> |
This file contains hidden or 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 | |
include 'conn.php'; | |
if (isset($_POST['submit']) ) { | |
$username = mysqli_real_escape_string($con,htmlspecialchars($_POST['username'])); // For Security Against Injectioins | |
$email = mysqli_real_escape_string($con,htmlspecialchars($_POST['email'])); | |
$mobile = mysqli_real_escape_string($con,htmlspecialchars($_POST['mobile'])); | |
$p1 = password_hash(mysqli_real_escape_string($con,$_POST['password']), PASSWORD_BCRYPT); | |
$p2 = password_hash(mysqli_real_escape_string($con,$_POST['cpassword']), PASSWORD_BCRYPT); | |
$emailquery = "SELECT * FROM `registration` where `email` = '$email' OR `username` = '$username';"; | |
$emailcount = mysqli_num_rows(mysqli_query($con,$emailquery)); | |
if ($emailcount>0) { | |
echo "Email already exist"; | |
} | |
else { | |
if ($p1===$p1) { | |
$inserquery = "INSERT INTO registration(username,email,mobile,password,cpassword) VALUES('$username','$email','$mobile','$p1','$p2');"; | |
if (mysqli_query($con,$inserquery)) { | |
echo '<script type="text/javascript"> alert("Inserted successfully");</script>'; | |
}else{ | |
echo '<script type="text/javascript">alert("Not inserted");</script>'; | |
} | |
}else{ | |
echo "passwrd are not match"; | |
} | |
} | |
} | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css"> | |
<title> </title> | |
</head> | |
<body> | |
<form action="" method="post"> | |
<div class="form-group w-25" > | |
<input type="text" name="user" value="<?php echo $_POST['name'];?>" class="form-control" placeholder="Full name" required=""> | |
</div> | |
<div class="form-group w-25"> | |
<input type="email" name="email" value="<?php echo $_POST['email'];?>" class="form-control" placeholder="Enter your email" required=""> | |
</div> | |
<div class="form-group w-25"> | |
<input type="tel" name="mobile" value="<?php echo $_POST['mobile'];?>" class="form-control" placeholder=" your Phone" required=""> | |
</div> | |
<div class="form-group w-25"> | |
<input type="password" name="password" degree="" class="form-control" placeholder="Enter your password" required=""> | |
</div> | |
<div class="form-group w-25"> | |
<input type="password" name="cpassword" value="" class="form-control" placeholder="confirm password" required=""> | |
</div> | |
<button type="submit" name="submit" class="btn btn-primary btn block">Create account</button> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment