Jump to content

I can't figure out why this isn't working


Craptacular

Recommended Posts

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=\"&#45; 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=\"&#43; 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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.