Niruban Nicholas Niruban Nicholas - 1 year ago 101
PHP Question

Error with submitting username and password for user registration

I'm new to PHP but I have some experience with HTML and JavaScript. This is my webpage, it's 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 doesn't add the validation and I can't find out why. What do I have to do to get the value from the textboxes only when submit is clicked? I've changed it around but I just can't find an answer.

Answer Source

You need to actually echo the strings.

<?php $nameErr;?>

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

<?php echo $nameErr;?>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download