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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:09:06+00:00 2026-05-23T21:09:06+00:00

I am trying to see why this if statement is not producing the correct

  • 0

I am trying to see why this if statement is not producing the correct message. What is supposed to happen, is that if a user selects a row that is not marked in the db as ‘In’ then the first message is displayed. If they forget to select an address or service level, then the else if sould be triggered. If all cases are correct, then perform the else statement. However, what is happening, is that the first message is being triggered when it is selected the first time and fires the Error. If a user then forgets to select an address or service then that Error is fired. If the user then meets all conditions, instead of performing the else statement, it displays the $boxstatus error, even though the conditions are true. Can someone please point out my error? Many thanks

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
header("Cache-Control: no-cache, must-revalidate" );
header("Pragma: no-cache" );
header("Content-type: application/json");
$json = "";
if ($boxstatus!="In") {
  $json .= "{\"Error\": \"ERROR: The box must be in the archive to enable a retrieval.\"}";
}
else if ($service == '' || $address == '') {
  $json .= "{\"Error\": \"ERROR: You must select a retrieval address and a service level.\"}";
}
else {
$json .= "{\n";
$json .= "\"address\": \"".$address."\",\n";
$json .= "\"service\": \"".$service."\",\n";
$json .= "\"box\": \"".$box."\"\n";
//$json .= "box: [\"". implode('","', $box) ."\"]\n";
$json .= "}\n";
}
echo $json;

ajax if it helps:

$.ajax({
               type: "POST",
               dataType: "json",
               url: "boxretrieve.php",
               data: "items="+itemlist+columns,
               success: function(data){
               if (data.Error) jAlert(data.Error);
                    else {
                jAlert("You have successfully retrieved\n\rBox: "+custref+"\n\r"+
                                 "Address: "+address+"\n\r"+
                                 "Service: "+service+"\n\r"+
                                 "Destroydate: "+destroydate);
               $("#flex1").flexReload();
               }
               }
             });

+++++UPDATE+++++++

Changed the second error to Error2 and did a condition in the ajax and all is now well. Thanks to everyone for there help.

  • 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-23T21:09:07+00:00Added an answer on May 23, 2026 at 9:09 pm

    I’ve tried your code by setting up your variables. It works! Nothing wrong with the conditions. You may want to check the result of your sql query or the way you show it on the browser.

    <?php
    $boxstatus = 'In';
    $service = '';
    $address = '';
    $json='';
    
    if ($boxstatus!="In") {
      $json .= "{\"Error\": \"ERROR: The box must be in the archive to enable a retrieval.\"}";
    }
    else if ($service == '' || $address == '') {
      $json .= "{\"Error\": \"ERROR: You must select a retrieval address and a service level.\"}";
    }
    else {
    $json .= "{\n";
    $json .= "\"address\": \"".$address."\",\n";
    $json .= "\"service\": \"".$service."\",\n";
    $json .= "\"box\": \"".$box."\"\n";
    //$json .= "box: [\"". implode('","', $box) ."\"]\n";
    $json .= "}\n";
    }
    
    echo $json;
    ?>
    

    The output:

    {"Error": "ERROR: You must select a retrieval address and a service level."}
    

    I also used your jQuery, I just changed your jAlert with simple alert. It works fine.

    <script type="text/javascript" src="jquery.js">
    </script>
    <script type="text/javascript">
    $(window).load(function(){
        $.ajax
        ({
           type: "POST",
           dataType: "json",
           url: "test.php",
           success: function(data)
           {
               if (data.Error) 
               {
                    alert(data.Error);
                }
                else 
                {
                    alert("You have successfully retrieved\n\rBox: "+custref+"\n\r"+
                                     "Address: "+address+"\n\r"+
                                     "Service: "+service+"\n\r"+
                                     "Destroydate: "+destroydate);
                   $("#flex1").flexReload();
               }
           }
        });
    });
    </script>
    

    I don’t know jAlert, but try using alert and tell me the result.

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

Sidebar

Related Questions

I'm looking around trying to see if anybody has asked this before. I don't
I am trying to execute this but cant see any result: <script> function init()
Im trying to use this page slider jquery plugin, you can see the demo
Can't seem to figure this out, see code below. Trying to make a GET
I'm trying to see if there is a way to build a Linq statement
i have this statement in access: SELECT * FROM accountsnew WHERE [Panels] not like
I've spent the better part of my day trying to solve this message while
i am running script as root and trying to see if user oracle has
(No this is not the same as my last post, I'm trying something different
I am trying to find an error in a massive SQL statement (not mine)

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.