javascript - how can return array values if first element is null in php -


i need insert array values database.but can not insert array values when first value of array null.how can fix problem

<form name=myform action="addcanteen.php" method=post> <table><tr><td width="11%"> date:</td><td width="89%"><input type="date" name="cdate" id="cdate"/></td></tr></table> <table border="1" bgcolor="#f5f9c1"> <tr> <!--<th>id</th>--> <th>name</th> <td><!--<input type="text" id="datepicker">-->   <input type="checkbox" id="selectall" name="chk[]"/></td> <td align="center">coffee</td>   <td align="center">tea</td> </tr> <?php while($row=mysql_fetch_array($result)) { ?> <tr> <?php /*?><td><?php echo $row['emp_id'];?></td><?php */?> <td><?php echo $row['emp_name'];?></td>  <td align="center"><input type="checkbox" class="name" name="chk1[]" value="<?php echo $row['emp_name'];?>"/></td>  <td><input type="text" name="coffee[]" id="coffee" value="" /></td> <td><input type="text" name="tea[]" id="tea" value=""/></td> </tr> <?php } ?> <tr> <td> </td> <td> </td> <td align="center"> <input type="submit" class="button" name="submit" id="submit" value="submit"/> </td> </tr> </table> </form> 

above form , insertion code.i inserted entire value if not null.but if first 1 null can not insert database

 <?php         include(dbcon.php);         date_default_timezone_set('utc');          $date=date("d");         $month=date("m");         $year=date("y");         $fd=date("d-m-y");         if(isset($_post['submit']))         {             $cdate=$_post['cdate'];          $checkbox1=$_post['chk1'];         $tea=$_post['tea'];         $coffee=$_post['coffee'];         ($i=0; $i<sizeof($checkbox1);$i++)          {         $query1="insert canteen(name,coffee,tea,date)values('".$checkbox1[$i]."','".$coffee[$i]."','".$tea[$i]."','$cdate')";         $sql1=mysql_query($query1);         }         }         header("location:canteen.php");         ?> 

this java script function select check box

$(function () {     // add multiple select / deselect functionality     $("#selectall").click(function () {         $('.name').attr('checked', this.checked);     });     // if checkbox selected, check select checkbox     // , viceversa     $(".name").click(function () {         if ($(".name").length == $(".name:checked").length) {             $("#selectall").attr("checked", "checked");         } else {             $("#selectall").removeattr("checked");         }     }); }); 

maybe... try this:

for ($i=0; $i<sizeof($checkbox1);$i++)  {   if($checkbox1[$i] != null && $coffee[$i] != null && $tea[$i]  != null) {     $query1="insert canteen(name,coffee,tea,date)values('".$checkbox1[$i]."','".$coffee[$i]."','".$tea[$i]."','$cdate')";     $sql1=mysql_query($query1);   } } 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -