Niruban Nicholas Niruban Nicholas - 1 month ago 4
HTML Question

Error with submitting php code

Im new to php but i have some experience with html and javascript. This is my webpage, its a simple register screen.

<!DOCTYPE html>
.error{color: #FF0000;}
$name = $password = $confirmPassword = $email = $phone = "";
$nameErr = $passwordErr = $confirmPasswordErr = $emailErr = $phoneErr = "";

//echo "insdie if";
$nameErr = "Name is required";
}else {
$name = $_POST["name"];
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
$nameErr = "Only letters and white space allowed";
$nameErr = "password is required";
$confirmPasswordErr = "Confirm password doesn't match password.";
}else {
$password = $_POST["password"];
if($password < 8){
$passwordErr = "Password should contain more than 8 characters";
$confirmPasswordErr = "Confirm password and password dont match";
}else {
$confirmPassword = $_POST["confirmPassword"];
if($confirmPassword != $password){
$confirmPasswordErr = "Confirm password and password dont match";

$nameErr = "Email is required";
}else {
$email = test_input($_POST["email"]);
echo "".$name."";

function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
<form method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<h1>Register to CabsOnline</h1>
<p>Please fill th fields below to complete your registration</p>
<td><input type="text" name="name"/><span class="error"><?php $nameErr;?></span></td>
<td><input type="password" name="password"/><span class="error"><?php $passwordErr;?></span></td>
<td>Confirm Password:</td>
<td><input type="password" name="confirmPassword"/><span class="error"><?php $confirmPasswordErr;?></span></td>
<td><input type="text" name="email"/><span class="error"><?php $emailErr;?></span></td>
<td><input type="text" name="phone"/><span class="error"><?php $phoneErr;?></span></td>


<input type="submit" value="Register"/>

<h4>Already registered?</h4><a href="login.php">Loging here</a>

The code doesnt add the validation and i cant find out why. Can someone please explain what i have to do to get the value from the textbox's only when submit is clicked? i've changed it around but i just cant find an answer.



You need to actually echo the strings.

<?php $nameErr;?>

on its own doesn't do anything, it should be

<?php echo $nameErr;?>