php - "Invalid argument" on posted array foreach loop -
yo, have simple foreach loop:
foreach ($_post['carid'] $carid) { $query = "delete cars carindex = ".$carid.""; echo $query; }
but i'm getting error: warning: invalid argument supplied foreach() in k:\xampp\htdocs\cars\deletecar.php on line 8
line 8 being:
foreach ($_post['carid'] $carid)
the array "($_post['carid']" created multiple checkboxes on page , posted using submit button form.
the form is:
<form name="input" action="delete.php" method="post"> <input type="submit" value="submit"> <while loop> <input type="checkbox" name="carid[]" value="'.$row['carindex'].'"> <end loop> </form>
the actual check box within loop based on mysql query.
the array made here sent page displays selected database records using foreach loop create statment query. exact same foreach not working.
i do:
$where = " "; foreach ($_post['carid'] $carid) { $where = $where." carindex = ".$carid." or"; } $where = substr($where, 0, -3);
and works fine.
i have sure wanna delete yes , no buttons.
the yes button have tried normal submit button so:
<form name="input" action="deletecar.php" method="post"> <input type="submit" value="yes" value="'.$_post['carid'].'"> </form>
but on submission, on deletecar.php page error: warning: invalid argument supplied foreach() in k:\xampp\htdocs\cars\deletecar.php on line 8
the full code deletecar.php is:
<?php $db = mysqli_connect('localhost', 'root', '', 'cdb') or die('error connecting'); echo $_post['carid']; foreach ($_post['carid'] $carid) { $query = "delete cars carindex = ".$carid.""; echo $query; } //header ("location: profile.php?username=".$_session['username']."") ?>
the top echo posted data echos out "array" far can tell getting data knows array. theres disabled redirect.
it simple, can't seem figure out.
form element name carid
missing. include in form
.
change:
<form name="input" action="deletecar.php" method="post"> <input type="submit" value="yes" value="'.$_post['carid'].'"> </form>
to:
<form name="input" action="deletecar.php" method="post"> <input type="hidden" name="carid" value="'.$_post['carid'].'"> <input type="submit" value="yes"> </form>
Comments
Post a Comment