Hey i just started to learn php and i have a new user form and its allowing blank username , pass, and email help please if (isset($_POST['submit'])) { // Form has been submitted. $errors = array(); // perform validations on the form data $required_fields = array('username', 'password','email'); $errors = array_merge($errors, check_required_fields($required_fields, $_POST)); $fields_with_lengths = array('username' => 30, 'password' => 30,'email' =>30); $errors = array_merge($errors, check_max_field_lengths($fields_with_lengths, $_POST)); $username = trim(mysql_prep($_POST['username'])); $password = trim(mysql_prep($_POST['password'])); $hashed_password = sha1($password); $email = trim (mysql_prep($_POST['email'])); if ( empty($errors) ) { $query = "INSERT INTO ausers ( username, hashed_password ,email ) VALUES ( '{$username}', '{$hashed_password}', '{$email}' )"; $result = mysql_query($query, $connection); if ($result) { $message = "Welcome To JobLance $username" ; } else { $message = "The user could not be created."; $message .= "<br />" . mysql_error(); } } else { if (count($errors) == 1) { $message = "There was 1 error in the form."; } else { $message = "There were " . count($errors) . " errors in the form."; } } } else { // Form has not been submitted. $username = ""; $password = ""; $email = ""; } ?> <h2>Create New User</h2> <?php if (!empty($message)) {echo "<p class=\"message\">" . $message . "</p>";} ?> <?php if (!empty($errors)) { display_errors($errors); } ?> <form action="myfirst.php" method="post"> PHP:
Add this: if (empty($username)) { $errors[] = 'Enter a username'; } PHP: ... right above this line: if ( empty($errors) ) { PHP: