Jump to content
Larry Ullman's Book Forums

Search the Community

Showing results for tags 'error array populate register'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Single Editions
    • Modern Javascript: Develop and Design
    • The Yii Book
    • Effortless Flex 4 Development
    • Building a Web Site with Ajax: Visual QuickProject
    • Ruby: Visual QuickStart Guide
    • C++ Programming: Visual QuickStart Guide
    • C Programming: Visual QuickStart Guide
    • Adobe AIR: Visual QuickPro Guide
  • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (5th Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)
    • PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide (3rd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (2nd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (1st Edition)
  • PHP for the Web: Visual QuickStart Guide
    • PHP for the Web: Visual QuickStart Guide (5th Edition)
    • PHP for the Web: Visual QuickStart Guide (4th Edition)
    • PHP for the Web: Visual QuickStart Guide (3rd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (2nd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (1st Edition)
  • Effortless E-commerce with PHP and MySQL
    • Effortless E-Commerce with PHP and MySQL (2nd Edition)
    • Effortless E-Commerce with PHP and MySQL
  • PHP Advanced: Visual QuickPro Guide
    • PHP Advanced and Object-Oriented Programming: Visual QuickPro Guide (3rd Edition)
    • PHP 5 Advanced: Visual QuickPro Guide (2nd Edition)
    • PHP Advanced: Visual QuickPro Guide
  • MySQL: Visual QuickStart Guide
    • MySQL: Visual QuickStart Guide (2nd Edition)
    • MySQL: Visual QuickStart Guide (1st Edition)
  • Other
    • Announcements
    • Newsletter, Blog, and Other Topics
    • Forum Issues
    • Social

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Found 1 result

  1. I am having trouble getting the errors to populate on my register script. I copied the code from chapter 9 explicitly and I am continuing to overlook what is causing the problem. The problem is that the correct error message does not populate, such as when there is no last name or email address, instead of expressing that, it just says that I have an error and does not say what the error is for; such as an empty field. mysql error messages work just fine. if ($_SERVER['REQUEST_METHOD'] == 'POST') { $errors = array(); //will handle/store every error msg, one for each form input improperly filled out if (empty($_POST['first_name'])) { $errors[] = 'you forgot to enter your first name.'; } else { $fn = trim($_POST['first_name']); } if (empty($_POST['last_name'])) { $errors[] = 'you forgot to enter your last name.'; } else { $ln = trim($_POST['last_name']); } if (empty($_POST['email'])) { $errors[] = 'you forgot to enter a email.'; } else { $e = trim($_POST['email']); } if (!empty($_POST['pass1'])) { if ($_POST['pass1'] != $_POST['pass2']) { $errors[] = 'your passwords do not match.'; } else { $p = trim($_POST['pass1']); } } else { $errors[] = 'you forgot to enter your password.'; } if (empty($errors)) { // if there are no errors // register the user in the database require ('mysqli_connect.php'); // connect to database //make the query $q = "INSERT INTO users_info (first_name, last_name, email, pass1, time) VALUES ('$fn', '$ln', '$e', SHA1('$p'), NOW() )"; $r = @mysqli_query ($dbc, $q); // run the query if ($r) { // if everything is ok //print message: echo '<h3>Thank You!</h3> <p>you are now registered.</p> <p><br /></p>'; } else { //public msg echo '<h2>system error</h2> <p class="error"> you could not register due to system error. sorry for the inconvenience.</p>'; //debugging msg echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>'; } //end of $r IF //close db connection mysqli_close($dbc); exit(); } else { //return error echo '<h1>Error!</h1> <p class="error">The following error(s) occurred:<br />'; foreach ($error as $msg) { // print each error. echo " - $msg<br />\n"; } echo '</p><p>Please try again.</p><p><br /><p>'; } // end of if (empty($error)) IF. }
×
×
  • Create New...