php forms validations
Posted: Sun Oct 19, 2008 5:24 pm
hello i have some problems with a php code i don't know how to do it
this is my actual code for the moment testing
php code
if i put
in form.php it will work
but if i want to echo on the page with the form it doesn't work
and i don't know how should i do the function to make the echo please can someone provide me with an explanation or a function ? thank you very much
this is my actual code for the moment testing
Code: Select all
<form method="POST" action="form.php">
Username: <input type="text" name="username" maxlength="10" />
<? echo (isset($errors['username'])) ? $errors['username'] : '' ?><br />
<input type="submit" name="submit" value="true" />
</form>Code: Select all
if($_POST['submit'] == 'true') {
$errors = array();
if(empty($_POST['username']) || strlen($_POST['username']) > 9) {
$errors['username'] = 'Your username is not the right length';
}
}Code: Select all
echo (isset($errors['username'])) ? $errors['username'] : ''but if i want to echo on the page with the form it doesn't work