Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7174827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:08:35+00:00 2026-05-28T16:08:35+00:00

I am trying to do form validation but when I try to print out

  • 0

I am trying to do form validation but when I try to print out the contents of an array when there is an error it doesnt output anything.

$errors = array();

if (strlen($password) >= 6) {
    array_push($errors, "Your password is not long enough! Must be over 6 characters!");
}

if(count($errors) !== 0) { 
...
} else {
    echo "There is errors<br/>"; 
    foreach($errors as $er){
        echo $er . "<br/>";
    }
} 

What I do get is “There is errors” so I know that the if else is working.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:08:36+00:00Added an answer on May 28, 2026 at 4:08 pm

    I just have to correct the argument of the if:

    if(count($errors) === 0) {
         // everything is okay
    } else {
        echo "There are errors<br/>"; 
        foreach($errors as $er){
            echo $er . "<br/>";
        }
    }
    

    In this way, when your error count is 0, the content of the if is executed. When it isn’t 0, the content of the else is executed and the errors are printed. It’s just the opposite of what you did.
    (I also corrected the sentence: it’s ‘there are errors’, not ‘there is errors’ :P)

    Furthermore, the other if is wrong as well, it should be the opposite:

    if (strlen($password) <= 6) {
    

    since you need to check when the password is less than 6 characters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am trying to set up form validation but keep receiving Parse error: syntax
I'm trying to create a form validation. I added @user.errors.add_to_base TEST to my controller,
I'm trying to use bootstrap with the jquery validation plugin but when I try
I am trying to use jQuery to setup a form validation, but theres this
I'm trying to user jQuery Validation plugin to validate a signup form, but I
I have been trying to figure out how all this validation works, but I
I am trying to do some very simple form validation checking for null or
Im trying to add a Jquery validation script to a form plugin for wordpress.
I'm trying to stop postback on form submit if my custom jQuery validation returns
I am trying to validate a form in MVC. I add custom errors to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.