pctn513 Posted February 15, 2014 Share Posted February 15, 2014 Hey everyone, I have a database that displays a list of users that have been added to a 'Favorites List'. The user has the ability to remove/delete users from the list using checkboxes and a delete button; however, when the user clicks the delete button after selecting the user they wish to delete, the page will refresh but the user still remains in the database instead of being delete. Can someone help me out? I have supplied my current code. <?php /// Connect to database. /// include_once("scripts/connect_to_mysql.php"); include_once("scripts/functions.php"); /// Start secure session. /// sec_session_start(); if (isset($_GET['id'])) { $id = preg_replace('#[^0-9]#i', '', $_GET['id']); } else if (isset($_SESSION['id'])) { $id = $_SESSION['id']; } else { header("location: logout.php"); exit(); } $id = preg_replace('#[^0-9]#i', '', $id); /// Grab information of user logged-in $displayList = ''; $sql_user_data = mysql_query("SELECT id FROM members WHERE id='$_SESSION[id]' LIMIT 1") or die (mysql_error()); while($row = mysql_fetch_array($sql_user_data)) { $userid = $row["id"]; } $sql_favorites_match = mysql_query("SELECT id, member_id, favorite_id FROM favorites WHERE member_id='$userid'") or die (mysql_error()); while($row = mysql_fetch_array($sql_favorites_match)) { $favid = $row["id"]; $member_id = $row["member_id"]; $favorite_id = $row["favorite_id"]; $displayList .='<div>Favorite User ID: '.$favorite_id.' <input id="checkbox[]" name="checkbox[]" type="checkbox" value='.$favid.'></div>'; } if(isset($_POST['favdelete'])) { $checkbox = $_POST['checkbox']; //from name="checkbox[]" $countCheck = count($_POST['checkbox']); for($i=0;$i<$countCheck;$i++) { $del_id = $checkbox[$i]; $sql = "DELETE from favorites where id = $del_id"; $result = $mysqli->query($sql) or die(mysqli_error($mysqli)); } header("Location: ./deletechk_test.php"); } ?> Link to comment https://forums.phpfreaks.com/topic/286221-help/ Share on other sites More sharing options...
Barand Posted February 15, 2014 Share Posted February 15, 2014 You are trying to use a mix of mysql and mysqli. You have to use one or the other, preferably mysqli Link to comment https://forums.phpfreaks.com/topic/286221-help/#findComment-1469072 Share on other sites More sharing options...
pctn513 Posted February 15, 2014 Author Share Posted February 15, 2014 I've switched to just mysql for now. This still does not resolve the issue. Link to comment https://forums.phpfreaks.com/topic/286221-help/#findComment-1469073 Share on other sites More sharing options...
Barand Posted February 15, 2014 Share Posted February 15, 2014 Where does $_POST['favdelete'] get sent from? And I do not see a form anywhere. Link to comment https://forums.phpfreaks.com/topic/286221-help/#findComment-1469075 Share on other sites More sharing options...
pctn513 Posted February 15, 2014 Author Share Posted February 15, 2014 Sorry, I didnt include my html code. Here it is: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Checkbox delete test</title> </head> <body> <?php print "$displayList"; ?> <br> <form action="deletechk_test.php" method="post" name="myForm"> <input name="favdelete" type="submit" value="Delete" /> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/286221-help/#findComment-1469077 Share on other sites More sharing options...
Barand Posted February 15, 2014 Share Posted February 15, 2014 The checkboxes are not inside the form Link to comment https://forums.phpfreaks.com/topic/286221-help/#findComment-1469078 Share on other sites More sharing options...
pctn513 Posted February 15, 2014 Author Share Posted February 15, 2014 Of course! how did I miss such a newbie mistake. Thanks for the advice. Link to comment https://forums.phpfreaks.com/topic/286221-help/#findComment-1469079 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.