<?php
extract($_POST);
include("database.php");
$sql = mysqli_query($conn, "SELECT * FROM register where Email='$email'");
if (mysqli_num_rows($sql) > 0) {
echo "Email Id Already Exists";
exit;
}
else (isset($_POST['save'])) {
$query = INSERT INTO register(First_Name, Last_Name, Email, Password)
VALUES ($$first_name, $$last_name, $email, md5($pass));
$sql = mysqli_query($conn, $query) or die("Could Not Perform the Query");
header("Location: login.php?status=success");
} else {
echo "Error.Please try again";
}
My PHP is a little rusty but this is what happens in principle (see comments ↓ )
<?php
extract($_POST);
include("database.php");
// ask the database for a record where the email field equals
// the exctracted $email from the $_POST variable
$sql = mysqli_query($conn, "SELECT * FROM register where Email='$email'");
if (mysqli_num_rows($sql) > 0) {
// if email already exists, echo that out and terminate the script
echo "Email Id Already Exists";
exit;
}
// if $_POST['save'] is set:
else (isset($_POST['save'])) {
// tell the database to save the new user with values extracted from $_POST:
$query = INSERT INTO register(First_Name, Last_Name, Email, Password)
VALUES ($$first_name, $$last_name, $email, md5($pass));
// try to connect to database
$sql = mysqli_query($conn, $query) or die("Could Not Perform the Query");
// if connection/save was successful, redirect to login page
// with "status=success" in GET parameter
header("Location: login.php?status=success");
} else {
echo "Error.Please try again";
}
If that doesn’t answer your question, you’ll have to be more specific about what confuses you.
2 Likes
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.