php - why iam getting blank screen in this code -


allmob.js:

$(document).ready(function() {     $(':checkbox').change(function() {          var result1 = [];           $(':checkbox:checked').each(function() {              result1.push($(this).val());          });          var url = "mob1.php"         if (result1.length > 0) {              //var fin = result1 ;             $.post(url, { contval: result1 }, function(data) {                 $('#result').html(data);             });         }         else {             $('#result').html("nothing checked");         }     }); }); 

if instead of passing result1 pass 1 $.post(url, { contval: 1 }, function(data) getting output , if pass result1 blank screen comes.

mob.php:

 <?php       $contval = $_post['contval'] ;       if ($contval == "1")      {           echo "1 checked" ;      }    if($contval == "2")       {       echo "2 selected" ;      } ?>    

allmob.php

   <?php     session_start();     ?>      <html>      <head>        <link rel="stylesheet" type="text/css" href="css/bootstrap.css">      <link rel="stylesheet" type="text/css" href="css/allmob.css">      <script type = "text/javascript="js/jquery1.11.3.js">                     </script>            <script type = "text/javascript" src ="js/allmob.js"></script>       </head>      <body>      <div class = "well">add2kart</div>      <div class = "container">      <div class = "row">     <div class = "col-lg-4">   <h5>price :</h5>     <input type = "checkbox" name = "price" value = "1">&#8377;1,000-&#8377;5,000</input><br>      <input type = "checkbox" name = "price" value = "2">&#8377;5,000-&#8377;10,000</input><br>          <input type = "checkbox" name = "price" value = "3">&#8377;10,000-&#8377;15,000</input><br>          <input type = "checkbox" name = "price" value = "between 15000 , 25000">&#8377;15,000-&#8377;25,000</input><br>          </div>             <div class = "col-lg-8">             <div id = "result" >            </div>        </div>       </div>      </body>       </html> 

selected checkbox handled allmob.js , value of selected checkbox sent mob.php want if value 1 checkbox selected in mob.php condition 1 print if bot 1 , 2 checkbox selected both conditions should print

try this...

$_post['contval'] array can't check it's value directly using "=="

<?php       $contval = $_post['contval'] ;       if (!empty($contval) &&  in_array("1", $contval))       {            echo "1 checked" ;      } ?>  

Comments