Created
May 22, 2017 09:35
-
-
Save rintoug/5d84de3354c13623db0bad759adf4b0a to your computer and use it in GitHub Desktop.
PHP User Registration Form
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 | |
try { | |
$conn = new PDO("mysql:host=localhost;dbname=tutsplanet", 'root', ''); | |
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | |
$password = password_hash($_POST['password'], PASSWORD_BCRYPT); //hashing password | |
$query = "INSERT INTO `customers` (`username`, `firstname`,`lastname`, `email`, `password`, `gender`) | |
VALUES (:username, :firstname,:lastname, :email, :password, :gender)"; | |
$stmt = $conn->prepare($query); | |
$stmt->bindParam('username', $_POST['username']); | |
$stmt->bindParam('firstname', $_POST['firstname']); | |
$stmt->bindParam('lastname', $_POST['lastname']); | |
$stmt->bindParam('email', $_POST['email']); | |
$stmt->bindParam('password', $password); | |
$stmt->bindParam('gender', $_POST['gender']); | |
$stmt->execute(); | |
header("Location:index.php?msg=1"); | |
} | |
catch(PDOException $e){ | |
echo "Connection failed: " . $e->getMessage();exit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment