Hi,
I am trying to create a variable in PHP that will represent an error message and in the case of an error the message will appear inside the HTML.
If you examine my code you will notice that on line 69 I have the following code:
<span style="color: red;">
<?= $Error_message; ?>
</span>
However this is not working correctly and I received the following error:
Undefined variable: Error_messag in C:\xampp\htdocs\eli_task\Connect.php on line 69.
For your convenience we are attaching our code to this form.
<?php
session_start();
if( isset($_SESSION[âuidâ]) || isset($_COOKIE[ârememberme_idâ])){
header(âlocation: members.phpâ);
}
$user = [
âidâ => 56,
ânameâ => âshimiâ,
âemailâ => â[email protected]â,
âpasswordâ => â123456â,
];
$error = ââ;
$emailRegex = â/^[\w-]+(.[\w-]+) @[a-z0-9-]+(.[a-z0-9-]+) (.[a-z]{2,3})$/iâ;
if(isset($_POST[âsUbmitâ])){
if(empty($_POST[âeMailâ]) || !preg_match ($emailRegex , $_POST[âeMailâ] ))
{
$Error_message = âYour email pattern is problematic or emptyâ;
}
elseif (empty($_POST[âpOswordâ]) || empty($_POST[âfIrstnameâ])){
$Error_message = âYou did not enter a password or a Nameâ;
}
elseif($user[ânameâ]<>$_POST[âfIrstnameâ] ){
$Error_message =âYour name does not equal the name on the systemâ;
}
elseif($user[âemailâ]<>$_POST[âeMailâ] || $user[âpasswordâ] <>$_POST[âpOswordâ]) {
$Error_message =âYou have an issue with your password or emailâ;
}
}
?>
<!DOCTYPE html>
<html lang=âenâ>
<head>
<meta charset=âUTF-8â>
<meta name=âviewportâ content=âwidth=device-width, initial-scale=1.0â>
<meta http-equiv=âX-UA-Compatibleâ content=âie=edgeâ>
<title>Welcome to my page</title>
</head>
<body>
<div id=âsignin-form-wrapperâ>
<form method=âpostâ action=âConnect.phpâ novalidate=ânovalidateâ>
What is your name?:<br>
<input type=âtextâ name=âfIrstnameâ>
<br>
What is your email:<br>
<input type=âemailâ name=âeMailâ required=ââ placeholder=âEnter a valid email addressâ>
<br>
What is your Pasword:<br>
<input type=âpasswordâ name=âpOswordâ>
<br>
<br>
<input type=âsubmitâ name=âsUbmitâ value=âSubmitâ>
<span style=âcolor: red;â>
<?= $Error_message; ?>
</span>
</form>
</div>
</body>
</html>
Looking forward for your help.