php - if statement producing incorrect result -


i trying see why if statement not producing correct message. supposed happen, if user selects row not marked in db 'in' first message displayed. if forget select address or service level, else if sould triggered. if cases correct, perform else statement. however, happening, first message being triggered when selected first time , fires error. if user forgets select address or service error fired. if user meets conditions, instead of performing else statement, displays $boxstatus error, though conditions true. can please point out 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: box must in archive enable retrieval.\"}"; } else if ($service == '' || $address == '') {   $json .= "{\"error\": \"error: must select retrieval address , 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 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 retrieved\n\rbox: "+custref+"\n\r"+                                  "address: "+address+"\n\r"+                                  "service: "+service+"\n\r"+                                  "destroydate: "+destroydate);                $("#flex1").flexreload();                }                }              }); 

+++++update+++++++

changed second error error2 , did condition in ajax , well. there help.

i've tried code setting variables. works! nothing wrong conditions. may want check result of sql query or way show on browser.

<?php $boxstatus = 'in'; $service = ''; $address = ''; $json='';  if ($boxstatus!="in") {   $json .= "{\"error\": \"error: box must in archive enable retrieval.\"}"; } else if ($service == '' || $address == '') {   $json .= "{\"error\": \"error: must select retrieval address , 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: must select retrieval address , service level."} 

i used jquery, changed jalert simple alert. 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 retrieved\n\rbox: "+custref+"\n\r"+                                  "address: "+address+"\n\r"+                                  "service: "+service+"\n\r"+                                  "destroydate: "+destroydate);                $("#flex1").flexreload();            }        }     }); }); </script> 

i don't know jalert, try using alert , tell me result.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -