php - array_keys() expects parameter 1 to be array, null given -


my form cannot update data, please me, display error on "array_keys() expects parameter 1 array, null given" in line 4 , "invalid argument supplied foreach()" in line 5 @ ramadan.php.

here want display data sql query , update query.

its work in web page in case cannot work..

my form

<form action="ramadan.php" method="post"> <? $result = mysqli_query($dbh,"select * ramadan id in (1, 2, 3)"); if(!$result) { die("database query failed: " . mysqli_error()); }    while($row = mysqli_fetch_assoc($result)) {     $id=$row['id'];     $ramadan=$row['ramadan'];     $date=$row['date'];     $taraweeh=$row['taraweeh'];  echo '   <tr>     <td><input type="text" name="ramadan['.$id.']" class="form-control" value="'.$ramadan.'"></td>     <td><input type="text" name="date['.$id.']" class="form-control" value="'.$date.'"></td>     <td><input type="text" name="taraweeh['.$id.']" class="form-control" value="'.$taraweeh.'"></td>   </tr> ';} ?>   <input type="submit" class="btn btn-success" name="submit" id="submit" value="submit"> </form> 

ramadan.php

include("../db.php"); global $dbh; if(isset($_post['submit'])){ $ids = array_keys($_post['name']);   foreach ($ids $id) {     $ramadan = mysqli_real_escape_string($dbh,$_post['ramadan'][$id]);     $date   = mysqli_real_escape_string($dbh,$_post['date'][$id]);     $taraweeh   = mysqli_real_escape_string($dbh,$_post['taraweeh'][$id]);     $id     = mysqli_real_escape_string($dbh,$id);     // update data in mysql database      $update = mysqli_query($dbh,"update ramadan set hl='$hl', ramadan='$ramadan', date='$date', taraweeh='$taraweeh' id = '$id'");  }    // if updated.  } 

you doing wrong, post contain arrays of ramadan date taraweeh

$_post['name'] 

will array in have next inputs in form

<input type="text" name="name[1]"  value="xxx"/> <input type="text" name="name[2]"  value="yyy"/> <input type="text" name="name[3]"  value="zzz"/> <input type="text" name="name[4]"  value="aaa"/> 

Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -