php - Invalid argument when passing checkbox array from GET to POST -
php novice here. goal to:
a) display table of booking options (fitness classes) dynamically database records, allow user select multiple options checkboxes against each row - bit's working.
b) pass checkbox selection table listing selected data on confirmation page. i'm getting error here: invalid argument supplied foreach().
c) update database when user hits second page's 'confirm' button.
research far uncovered this advice on using $_get , $_post achieve array.
my checkbox code on initial page:
echo '<form action="makebooking.php" method="get">'; echo '<td><input type="checkbox" name="class_id[]" value=' . $row['class_id'] . '</td></tr>';
the foreach statement error comes code generates table of choices on second page:
//check if set classes.php if (isset($_get['class_id'])) { // grab score data foreach($_get['class_id'] $class_id) { $_get['class_id'] = $class_id; } } //table header echo '<table class="table table-bordered table-hover">'; echo '<thead><tr><th>date</th><th>time</th><th>venue</th><th>who\'s going?</th> <th>add someone</th></tr></thead>'; //create form echo '<form method="post" action="' . $_server['php_self'] . '">'; //get class ids use in post foreach ($_get['class_id'] $class_id) { $sql = "select class_id, date_format(date, '%a, %d %b') new_date, date_format(time, '%h:%i') new_time, venue classes class_id = '$class_id'"; $data = mysqli_query($dbc, $sql); //--------------------------------------------------------------------------------- //get table data while ($row = mysqli_fetch_array($data)) { $date = $row["new_date"]; $time = $row["new_time"]; $venue = $row["venue"]; $class_id = $row["class_id"]; } //--------------------------------------------------------------------------------- //show table of selected classes echo '<input type="hidden" name="id" value= ' . $class_id . ' />'; echo '<td>' . $date . '</td>'; echo '<td>' . $time . '</td>'; echo '<td>' . $venue . '</td>'; echo '<td>' . $username . '</td>'; echo '<td><button class="btn btn-mini" type="button"><i class="icon-user"></i><i class="icon-plus"</i></button></td></tr>'; } echo'</table>'; // make booking button echo '<input type="submit" name="submit" class="btn btn-large btn-primary pull-right" value="confirm">'; echo '</form>'; }
full code of both pages @ this pastebin. error-fixing advice gratefully accepted!
figured out had been declaring variables in if/else loops made them inaccessible other parts of code.
i added hidden input arrays both tables validate input. required string-to-integer conversion of class id in order update db selected data.
full fixed code here struggling similar.
Comments
Post a Comment