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.
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.
The output:
I also used your jQuery, I just changed your
jAlertwith simplealert. It works fine.I don’t know
jAlert, but try usingalertand tell me the result.