php - Multiple checkbox database insert with mysql prepare -
i have checkboxes generated code:
while($row = $result->fetch_assoc()) { echo "<input type='checkbox' name='branch[]' value='".$row['id']."'> ".$row['name']."<br>"; }
and need insert value of every checkbox in mysql database. code have inserts every checkbox $member_id
, $branch
inserted 0. doing wrong?
$sql = "select id members email='$email'"; $result = mysqli_query($mysqli,$sql); $row = mysqli_fetch_array($result,mysqli_assoc); $member_id = $row["id"]; $checked_arr = $_post['branch']; $branch_count = count($checked_arr); ($i = 0; $i < $branch_count; $i++) { if ($insert_stmt_branch = $mysqli->prepare("insert members_branch (member, branch) values (?, ?)")){ $insert_stmt_branch->bind_param('ss', $member_id, $branch); if (! $insert_stmt_branch->execute()) { echo "error: branch insert"; } } }
at start of loop, forgot add:
$branch = $checked_arr[$i];
also, don't have verify query looking email address returns value. if no account found, $member_id value blank.
Comments
Post a Comment