Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

can someone please help me with a php code to valid the email for an online stor

ID: 3815737 • Letter: C

Question

can someone please help me with a php code to valid the email for an online store website after a customer registers for an acoount from the code below. just add the validation code into the code below( validate the information added is valid format basically). and all add a user name to log in?

require("connect.php");
if($_POST['submit'])
{
$login = $_POST['login'];

   /* algorithm to hash the password*/
$hashed_password = password_hash($password, PASSWORD_DEFAULT);

$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$dob = $_POST['dob'];
$gender = $_POST['gender'];
$specialisation = $_POST['specialisation'];
$clinic = $_POST['clinic'];
$address = $_POST['address'];
$city = $_POST['city'];
mysql_query("insert into dusers values ('$login', '$password', '$firstname', '$lastname', '$dob', '$gender', '$specialisation', '$clinic', '$address', '$city')") or die(mysql_error("Unable to insert Values"));
  
echo "Registration Successful."; // print statement to user
}
echo "";
//}
?>

Explanation / Answer

Add the Username in the code:

if($_POST['submit'])
{
$login = $_POST['login'];

   /* algorithm to hash the password*/

$username = $_POST['username'];

$hashed_password = password_hash($password, PASSWORD_DEFAULT);

$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$dob = $_POST['dob'];
$gender = $_POST['gender'];
$specialisation = $_POST['specialisation'];
$clinic = $_POST['clinic'];
$address = $_POST['address'];
$city = $_POST['city'];

The below Code will Come before your Insert Query:

Validation of the Input in form

if($firstname =="") { $errorMsg= "error : You did not enter your First name."; }

elseif($lastname == "") { $errorMsg= "error : You did not enter your last name."; }

elseif(!ctype_alnum($lastname) && $lastname == "") { $errorMsg= "error : You did not enter Correct UserName"; } // To check username is alphanumeric

elseif(is_numeric(trim($dob)) == false){ $errorMsg= "error : Please enter correct date of birth."; }

elseif($gender != 'male' && $gender != 'female') { $errorMsg= "error : You did not entered Correct Gender."; }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote