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 6053531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:03:02+00:00 2026-05-23T08:03:02+00:00

I’m trying to figure out how i can fix this becasue the post parameters

  • 0

I’m trying to figure out how i can fix this becasue the post parameters of the form are: answer1[2], and answer2[4]. The number inside the brackets represent the id of the question it belongs to. Reason I need to know how to do this is because its not returning an error for the answers when its an empty form submission.

if((empty($_POST['answer1'])) || (trim($_POST['answer1'])=="") || ($_POST['answer1'] == NULL) || (!isset($_POST['answer1']))){$errors = "yes";}
if((empty($_POST['answer2'])) || (trim($_POST['answer2'])=="") || ($_POST['answer2'] == NULL) || (!isset($_POST['answer2']))){$errors = "yes";}

// Error checking, make sure all form fields have input
if ($errors == "yes") {

    // Not all fields were entered error
    $message = "You must enter values to all of the form fields!";

    $output = array('errorsExist' => true, 'message' => $message);

}
  • 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-23T08:03:02+00:00Added an answer on May 23, 2026 at 8:03 am

    You wrote that you have problems to understand what is going on. So let’s check one of the if-clauses in depth:

    if((empty($_POST['answer1'])) || (trim($_POST['answer1'])=="") || ($_POST['answer1'] == NULL) || (!isset($_POST['answer1']))) { ...
    

    This can be much simpler written as:

    if (empty($_POST['answer1']) || trim($_POST['answer1'])=="") { ...
    

    That’s because NULL values are empty() and !isset(...) values are empty as well. You had already checked that in the first, so no need to check it again.

    Then there is no need to add brackets around everything. Add them only when actual needed, to make your code easier to read.

    Let’s change the code based on that:

    if (empty($_POST['answer1']) || trim($_POST['answer1'])=="") {$errors = "yes";}
    if (empty($_POST['answer2']) || trim($_POST['answer2'])=="") {$errors = "yes";}
    
    // Error checking, make sure all form fields have input
    if ($errors == "yes") {
    

    Next part is the $errors variable. There is no need to make it say yes and no, while your mean true or false. Next to that, the variable should be initialized for the case that everything went through ok. Let’s change the code a bit more:

    $errors = false;
    if (empty($_POST['answer1']) || trim($_POST['answer1'])=="") {$errors = true;}
    if (empty($_POST['answer2']) || trim($_POST['answer2'])=="") {$errors = true;}
    
    // Error checking, make sure all form fields have input
    if ($errors) {    
        // Not all fields were entered error
        $message = "You must enter values to all of the form fields!";
    
        $output = array('errorsExist' => true, 'message' => $message);
    
    }
    

    So now the code looks a bit better to find your actual error. To find the error, you need to inspect which values are actually submitted to your form:

    echo '<pre>', htmlspecialchars(print_r($_POST, true)), '</pre>'; die();
    

    Request the page again and you will see which data you have submitted so you can check whether or not you error-check the right fields.

    Another method is to expect that all submissions have errors. So the default would be true. Then only if all fields do validate, $errors is set to false.

    So in your case, if you do not do the right error-checking your response will always return no errors, even the form in practice has. That’s why you should control if your error checks are actually working.


    According to your feedback in comment, it’s clear that you need to reference the item inside the answer1 and answer2 post field. You just have checked the wrong field.

    So just replace $_POST['answer1'] with $_POST['answer1'][2] and the same for the other answer. This is the example if clause for answer1:

    if (empty($_POST['answer1'][2]) || trim($_POST['answer1'][2])=="") { ...
                               ^^^                           ^^^
    

    Just always test the right variables and it should work like expected.

    Related: How do I create a server-side form submission script that has client-side characteristics?

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text

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.