php - deleting a member registered in the members database -
i have database setup register members members area of site. can echo of registered members checkbox can choose delete individual member admin page, cant seem figure out how member chosen deleted when submit button clicked. have tried on single page , on 2 page process, first page lists members checkbox works point of choosing member deleted, difficulty seem having getting members detail passed delete section of code. assist me please.
here delete_user.php lists members checkbox
<?php include_once 'db_connect.php'; include_once 'functions.php'; sec_session_start(); //display users info checkbox delete $sql = "select * `members` limit 0, 30 "; $result = mysqli_query($mysqli, $sql); while($row = mysqli_fetch_array($result)) { echo '<input type="checkbox" value="' .$row['username'] . '" name="delete[]" />'; // echo '<input type='checkbox' value='' .$row['adminid'] . '' name='delete[]' />'; echo ' ' .$row['username']; echo ' ' .$row['email']; echo '<br />'; } ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>delete member</title> </head> <body> <form> <input name="submit" type="submit" formaction="delete_user.inc.php" formmethod="post" value="delete user"> </form> </body> </html>
here process page delete_user.inc.php
<?php include_once 'db_connect.php'; include_once 'functions.php'; sec_session_start(); if ($_server["request_method"] == "post") { foreach($_post['delete'] $delete_user) { $sql = "delete members memberid = '$delete_user'"; mysqli_query($mysqli, $sql) or die ('die now'); } echo 'user has been deleted.<br />'; } ?>
you must render checkboxes inside form:
<?php include_once 'db_connect.php'; include_once 'functions.php'; sec_session_start(); //display users info checkbox delete $sql = "select * `members` limit 0, 30 "; $result = mysqli_query($mysqli, $sql); ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>delete member</title> </head> <body> <form type="post" action="delete_user.inc.php"> <?php while($row = mysqli_fetch_array($result)): ?> <label> <?php echo $row['username']; ?> - <?php echo $row['email']; ?> <input type="checkbox" value="<?php echo $row['memberid']; ?>" name="delete[]" /> </label> <?php endwhile; ?> <input name="submit" type="submit" value="delete user" /> </form> </body> </html>
then on delete process:
<?php include_once 'db_connect.php'; include_once 'functions.php'; sec_session_start(); if (isset($_post['submit'])) { foreach($_post['delete'] $delete_user) { $sql = "delete members memberid = ?"; $stmt = $mysqli->prepare($sql); $stmt->bind_param('i', $delete_user); $stmt->execute(); } echo 'user has been deleted.<br />'; } ?>
Comments
Post a Comment