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

  • Home
  • SEARCH
  • 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 9006113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:19:35+00:00 2026-06-16T01:19:35+00:00

I have a registration form on a website, the registration calls a function which

  • 0

I have a registration form on a website, the registration calls a function which accepts the $_POST values as arguments. While going through the usual checks, if an error is found it uses a function in the error message class which sets the error, and also increments the errorcounter variable.
This function accepts two arguments: the field and the error message (stored in an array).

    $errmsg->setError("firstname", "You must enter your name");

setError() sets the error:

    function setError($field, $errMsg){
        $this->errors[$field] = $errMsg;
    }

The register function checks to see if the error counter has been increased, if not it registers the account, if yes then it redirects back to the register page.

The register page uses a function in the errmsg class to show any errors:

    $errmsg->showError("firstname");
    // Argument being the field name.

This function should display any error messages that have been set:

    function showError($field) {
        if (isset($this->errors[$field])) {
            return $this->errors[$field];
        } else {
            return "";
        }
    }

So, you can see if the array has the index defined it should display the value, if not, display nothing.

The problem I’m having is that nothing is being displayed even when there is an error.

I’ve tried echoing out $errmsg->errors[‘firstname’]; in the register function if the error counter is > 0, and it displays the correct message. So I know the array key is being set, also if I change the else statement to return a string if the array key doesn’t exist it also works fine. So for some reason the value is being set, then lost again once the page reloads.

I also tried creating a function in the error message class to return the array which can be called by the register function when errors have been found:

    function getErrorArray(){
        return $this->errors;
    }

This also did nothing. To be 100% certain the array key exists at the time of running the register function I tried this:

    if ($errors > 0) {
        if(isset($errmsg->errors['firstname'])) {
            header("Location: ".$session->referrer);
        } else {
            header("Location: http://www.google.com");
        }

As expected, if there is an error (the error I’m working on here is an empty string) it redirects back and should show the message and when the field contained a value it redirected to Google.

I’ve also tried using:

    if(array_key_exists($field,$this->errors))

instead of:

    if(isset($errmsg->errors['firstname']))

I really don’t understand why this isn’t working, is it a scope issue? Should I maybe be storing this in $_SESSION? Any pointers would be greatly appreciated. Thanks.

  • 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-06-16T01:19:37+00:00Added an answer on June 16, 2026 at 1:19 am

    Yes, you should be storing this in $_SESSION. PHP variables only exist in the scope of the current request. As soon as the request is completed the variables are lost. And redirecting creates a new request.

    You could also show the error during the same request (when user posts the data to your server).

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

Sidebar

Related Questions

I have registration form on my website that, using jquery I append default values
I have created Login forms and registration forms for a website. The form is
i have a registration form which contains a postalcode and a country drop down
The website has a normal registration form which allows users to register and the
I'm creating a registration form on my school project website. I have given a
I have a registration form for a website that needs to check if an
I'm going through a tough decision (at least for me)... My website would have
I have a registration form which validates the users email with JS and PHP
I have a registration form on my website and I have 3 input boxes
We have a registration form for a service on our website. For that form

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.