So I have created a from which has 2 inputs. a text box where the user can type his username and a text box were he types in his password. then the PHP validation where if the text box for Username is empty then give an error message or if there is text in it, see if the text contains only numbers. if it does not give an error message again. The PHP validation for the password is the same principal. btw the forms loads to the same page as to where it is being created. But for some reason when it loads onto the broswer (loads fine) and I type in sybols on the Username text field and hit submit, the error does not come up. I really hope you guys can spot the problem cause this is driving me crazy.
<!DOCTYPE html>
<html>
<head>
<style>
.error {
color: red;
}
</style>
<title>Register</title>
</head>
<body>
<form action="#" method="POST">
<h1 id="Signup">Sign Up</h1>
<input type="text" name="Username" placeholder="Please Enter a Username">
<span class="error"><? echo $errorusername;?></span>
<br>
<input type="password" name="Password" placeholder="Please Enter a Password">
<span class="error"><? echo $errorpass;?></span>
<br>
<input type="Submit" id ="Submit">
</form>
</body>
</html>
<?php
$errorpass = "";
$errorusername = "";
if (isset($_POST['Submit']))
{
if (empty($_POST['Username']))
{
$errorusername = "name is required";
}
else
{
$Username = $_POST['Username'];
if (!preg_match("/^[a-zA-Z ]*$/", $Username))
{
$errorusername = "Only numbers allowed";
}
}
if (empty($_POST['password']))
{
$errorusername = " A password is required";
}
else
{
$password = $_POST['password'];
if (!preg_match("/^[a-zA-Z ]*$/", $password))
{
$errorpass = "Need to contain numbers and symbols";
?>