Creating Database Connection
save this as config.php
Creating Registration Form
save this as index.php
Inserting Data to Database
save this as register.php
Output
save this as config.php
PHP:
$database = new PDO ("mysql:host=localhost;dbname=db_name", 'root', 'user_pw');
Creating Registration Form
save this as index.php
PHP:
<div>
<form method="POST" action="register.php">
<div class="form-group">
<label>Email Address</label>
<input type="email" name="email" class="form-control" placeholder="Email Address" required>
</div>
<div class="form-group">
<label>Password</label>
<input type="password" name="password" class="form-control" placeholder="Password" required>
</div>
<div class="form-group">
<label>Re-type Password</label>
<input type="password" name="re_password" class="form-control" placeholder="Re-type Password" required>
</div>
<button type="submit" name="btn_submit" class="btn btn-primary">Submit</button>
</form>
</div>
Inserting Data to Database
save this as register.php
PHP:
require_once ('config.php');
if (isset($_POST['btn_submit'])) {
$email = $_POST['email'];
$password = md5($_POST['password']);
$re_password = md5($_POST['re_password']);
if ($password != $re_password) {
echo "<script>alert('Your Password does not match . . .'); window.location = 'index.php' </script>";
} else
{
$database->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$insert_query = "INSERT INTO tbl_user (email, password, re_password)
VALUES (?, ?, ?)";
$insert = $database->prepare($insert_query);
$insert->execute(array($email, $password, $re_password));
echo "<script>alert('Account successfully added!'); window.location='index.php'</script>";
}
}
Output
Attachments
-
You do not have permission to view the full content of this post. Log in or register now.