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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:56:16+00:00 2026-06-18T08:56:16+00:00

I’m unable to solve the logical error in the code. I’m not sure what

  • 0

I’m unable to solve the logical error in the code. I’m not sure what is wrong though it seems the logic is correct

This is my php:

<?php require_once("includes/connection.php"); ?>
<?php
include_once("includes/form_functions.php");
if(isset($_POST['submit']))
{
    $errors = array();
    if(isset($_POST['txtSpace']))
    {
        $choice_spc_port = $_POST["txtSpace"];
    }
    if(isset($_POST['txtNumber']))
    {
        $choice_no = $_POST["txtNumber"];
    }
    if(isset($_POST['txtLocation']))
    {
        $choice_loc = $_POST["txtLocation"];
        if($choice_loc =="txtSetXY")
        {
            $x = $_POST["txtXLocation"];
            $y = $_POST["txtYLocation"];
            if($x == "")
            {
                $message = "You forgot to enter X Value";
            }
            elseif($y == "")
            {
                $message = "You forgot to enter Y Value";
            }
            else
            {
                $choice_loc = $x . "," . $y;
            }
        }
    }
    $user_name = $_POST["txtUserName"];
    $user_email = $_POST["txtUserEMail"];
    $animal_name = $_POST["txtAnimalName"];
    $disp_msg = $_POST["txtDispMsg"];
    $comments = $_POST["txtComments"];
    if(!isset($_POST['txtSpace']))
    {
        $message = "Please select Space Portion";
    }
    elseif(!isset($_POST['txtNumber']))
    {
        $message = "Please select the number of animals";
    }
    elseif(!isset($_POST['txtLocation']))
    {
        $message = "Please select the desired location of animal";
    }
    elseif($user_name == "")
    {
        $message = "Please enter your name.";
    }
    elseif($user_email == "")
    {
        $message = "Please enter your email.";
    }
    elseif($animal_name == "")
    {
        $message = "Please enter the name of the animal.";
    }
    elseif($disp_msg == "")
    {
        $message = "What message you want to dedicate to the animal?.";
    }
    else
    {
        // validation
        $required_fields = array('txtUserName','txtUserEMail','txtAnimalName','txtDispMsg');
        $errors = array_merge($errors, check_required_fields($required_fields, $_POST));
        $user_name = trim(mysql_prep($_POST['txtUserName']));
        $user_email = trim(mysql_prep($_POST['txtUserEMail']));
        $animal_name = trim(mysql_prep($_POST['txtAnimalName']));
        $disp_msg = trim(mysql_prep($_POST['txtDispMsg']));

        if(empty($errors))
        {
            /*if($choice_loc == "txtSetXY")
            {
                $x = $_POST["txtXLocation"];
                $y = $_POST["txtYLocation"];
                $choice_loc = $x . "," . $y;
            }*/
            if($choice_no == "other")
            {
                $choice_no = $_POST["other_field"];
            }

            $insert = "INSERT INTO db_form (db_space_portion, db_number, db_location, db_user_name, db_user_email, db_animal_name, db_message, db_comments) VALUES ('{$choice_spc_port}', '{$choice_no}', '{$choice_loc}', '{$user_name}', '{$user_email}','{$animal_name}','{$disp_msg}','{$comments}')";
            $result = mysql_query($insert);
            if($result)
            {
                echo("<br>Input data is succeed");
            }
            else
            {
                $message = "The data cannot be inserted.";
                $message .= "<br />" . mysql_error();
            }
        }
        else
        {
            if(count($errors) == 1)
            {
                $message = "There was 1 error on the form.";
            }
            else
            {
                $message = "There were " . count($errors) ." errors on the form.";
            }
        }
    }
}
else
{
    $user_name = "";
    $user_email = "";
    $disp_msg = "";
    $comments = "";
}
    ?>
     <!DOCTYPE html>
     <html lang="en">
     <head>
     <title>Test Form</title>
     <meta charset="utf-8">
    <link rel="stylesheet" href="css/reset.css" type="text/css" media="all">
    <link rel="stylesheet" href="css/layout.css" type="text/css" media="all">
    <link rel="stylesheet" href="css/style.css" type="text/css" media="all">
    <script type="text/javascript" src="js/jquery-1.9.0.min.js" ></script>
    <script type="text/javascript" src="js/cufon-yui.js"></script>
    <script type="text/javascript" src="js/cufon-replace.js"></script>
    <script type="text/javascript" src="js/Copse_400.font.js"></script>
    <script type="text/javascript" src="js/imagepreloader.js"></script>
    <script type="text/javascript" src="js/functions.js"></script>
     <!--[if lt IE 9]>
    <script type="text/javascript" src="js/ie6_script_other.js"></script>
       <script type="text/javascript" src="js/html5.js"></script>
     <![endif]-->
        </head>
       <body id="page5">
       <!-- START PAGE SOURCE -->

      <div class="body7">
       <div class="main">
      <section id="content">
      <div class="wrapper">
        <article class="col24">
       <div class="pad1">
        <h4>Kindly Fill the form</h4>
        <?php if(!empty($message)){ echo $message; } ?>
        <?php if(!empty($errors)){ echo display_errors($errors);}?>
        <form id="TestForm" name="TestForm" method="post" action="form.php">
          <div>

          <div  class="wrapper"> <strong><span>*</span> Desired Space</strong>
            <div class="formText">
              <input type="radio" name="txtSpace" value="RJ"/>Space Top<br />
              <input type="radio" name="txtSpace" value="SM" />Space Bottom<br />
              </div>
            </div>

            <div class="wrapper"> <strong><span>*</span> Select the Number</strong>
            <div class="formText">
              <input type="radio" name="txtNumber" value="100"/>100
              <input type="radio" name="txtNumber" value="200"/>200
              <input type="radio" name="txtNumber" value="500"/>500
              <input type="radio" name="txtNumber" value="1000"/>1000
              <input type="radio" name="txtNumber" value="10000"/>10000
              <input type="radio" name="txtNumber" value="other"/>other
              <input type="text" name="other_field" id="other_field" onblur="checktext(this);"/>
            </div>
            </div>

            <div class="wrapper"> <strong><span>*</span> Select X & Y Value</strong>
                <div class="formText">
                <input type="radio" name="txtLocation" value="txtSetXY"/> Specify Photo Location<br />
                    <div style="padding-left:20px;">
                    X: <input type="text" id="locField" name="txtXLocation"><br />
                    Y: <input type="text" id="locField" name="txtYLocation"><br />
                    </div>
                    <input type="radio" name="txtLocation" value="Default"/>Default
                </div>

            </div>


            <div class="wrapper"> <strong><span>*</span> Your Name:</strong>
              <div class="bg">
                <input type="text" class="input" name="txtUserName">
              </div>
            </div>
            <div class="wrapper"> <strong><span>*</span> Your Email:</strong>
              <div class="bg">
                <input type="text" class="input" name="txtUserEMail">
              </div>
            </div>
            <div class="wrapper"> <strong><span>*</span> Name of the animal:</strong>
              <div class="bg">
                <input type="text" class="input" name="txtAnimalName">
              </div>
            </div>

            <div class="wrapper">
            <div class="textarea_box"> <strong><span>*</span> The Message you want for your favourite animal:</strong>
                <textarea name="txtDispMsg" cols="1" rows="1"></textarea>
            </div>
            </div>

            <div class="wrapper">
            <div class="textarea_box"> <strong>Comments:</strong>
                <textarea name="txtComments" cols="1" rows="1"></textarea>
            </div>
            </div>

            <input type="submit" name="submit" value="Submit"> 
           </div>
        </form>
      </div>
    </article>
  </div>
</section>
 </div>
</div>
</body>
 </html>

Errors:

Check this php fiddle here.

line 25. This is never shown even if I leave x textfield blank
$message = “You forgot to enter X Value”;

same is with line 29. This is never shown even if I leave y textfield blank
$message = “You forgot to enter Y Value”;

However if I enter the values in x and y textfield i.e. in txtXLocation and in txtYLocation they are being saved in db meaning it is just not checking the validation.

Thanks in advance

  • 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-18T08:56:18+00:00Added an answer on June 18, 2026 at 8:56 am

    make sure you have connection.php file in includes folder and you have given correct path to reach that file.

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

Sidebar

Related Questions

I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.