Skip to content

Instantly share code, notes, and snippets.

@rintoug
Created May 22, 2017 09:35
Show Gist options
  • Save rintoug/5d84de3354c13623db0bad759adf4b0a to your computer and use it in GitHub Desktop.
Save rintoug/5d84de3354c13623db0bad759adf4b0a to your computer and use it in GitHub Desktop.
PHP User Registration Form
<?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