Craptacular Posted May 17, 2012 Share Posted May 17, 2012 I know this is something I am just overlooking, but please help. I can't seem to get the selected item in the dropdownlist that is being populated from a database to be deleted. Here is the add_delete_users.php <?php require('config.php'); $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAMETWO); if (mysqli_connect_errno()) { die("Connection Failed"); } if (isset($_GET['pageno'])) { $pageno = $_GET['pageno']; } else { $pageno = 1; } // if ?> <!DOCTYPE html> <html> <head> <title>Manage Users</title> <link type="text/css" rel="stylesheet" href="/css/layout.css" /> <link type="text/css" rel="stylesheet" href="/css/admin.css" /> <!--[if lte IE 7]><link rel="stylesheet" href="/css/adminie7.css" type="text/css" media="screen" /><![endif]--> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript" src="/js/contentArea.js"></script> <script type="text/javascript"> $(document).ready(function() { $('#content .row:odd').addClass('odd'); $('#content .row:even').addClass('even'); }); </script> </head> <body id="index"> <div class="container-12"> <h1>Manage Users</h1> <div id="content"> <ul id="statuses"> <li <?php if ($status === "") {echo "class=\"current_page\"";}?>><a href="index.php?&status=" id="nav-new">New</a></li> <li <?php if ($status === "assigned") {echo "class=\"current_page\"";}?>><a href="index.php?&status=assigned" id="nav-assigned">Assigned</a></li> <li <?php if ($status === "completed") {echo "class=\"current_page\"";}?>><a href="index.php?&status=completed" id="nav-completed">Completed</a></li> <li><a href="bought.php">Bought</a></li> <li class="current_page"><a href="add_delete_users.php">Users</a></li> </ul> <div class="clear"></div> <?php $sql = "SELECT * FROM users"; $result = mysqli_query($mysqli, $sql) or trigger_error("SQL", E_USER_ERROR); while ($row = mysqli_fetch_array($result)) { $name = $row['name']; $options.="<OPTION VALUE=". $name .">". $name ."</option>"; } echo"<lable><strong>Delete User</strong></lable><form class=\"delete-form\" method=\"post\" action=\"delete_user.php\"><select name=\"user_name\" id=\"user_name\">\n" . $options . "</select> <input type=\"submit\" value=\"- Delete User\" /></form><br /><br />"; echo"<lable><strong>Add User</strong></lable><form class=\"add-form\" method=\"post\" action=\"add_user.php\"> <input type=\"hidden\" name=\"user_id\" value=\"\" /><br /> <lable for=\"user_name\">User Name: </lable><input type=\"text\" name=\"user_name\" value=\"\" /><br /> <lable for=\"email\">Email: </lable><input type=\"text\" name=\"email\" value=\"\" /><br /> <input type=\"hidden\" name=\"password\" value=\"2f0727a8fd0c695e52bfa79a97b6c08ab418c1db\" /> <lable for=\"name\">Name: </lable><input type=\"text\" name=\"name\" value=\"\" /><br /> <input type=\"hidden\" name=\"privileges\" value=\"admin\" /><br /> <input type=\"submit\" value=\"+ Add User\" /></form>"; mysqli_close($mysqli); ?> </div> </div> </div> </body> </html> and here is the delete_user.php that is being called after the user presses the delete button. <?php require('config.php'); $user_name = ($_POST['options']); // Connect to Database to store information $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAMETWO); if (mysqli_connect_errno()) { printf("Connect Failed: %s\n", mysqli_connect_error()); } else { $sql = "DELETE FROM users WHERE name = $user_name"; $res = mysqli_query($mysqli, $sql); echo "$user_name has been deleted!<br />"; echo "<a href=\"add_delete_users.php\">Go back to Manage more users</a><br /> <a href=\"index.php?&status=\">Go back to the main page</a><br />"; mysqli_close($mysqli); } // End Database interactions ?> Go easy on me. At this point my brain is a bit fried... I just need someone else's eyes on it at this point. Thanks in advance! Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted May 17, 2012 Share Posted May 17, 2012 When posting code, enclose it within the forum's . . . BBCode tags. Quote Link to comment Share on other sites More sharing options...
Craptacular Posted May 17, 2012 Author Share Posted May 17, 2012 okay. This was my first post... Wasn't sure what to do. Thanks Quote Link to comment Share on other sites More sharing options...
Barand Posted May 17, 2012 Share Posted May 17, 2012 As you have posted the question again, mark this as "Solved" so people don't wast time responding Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.