Code: Select all
<html>
<font size="1" face="Verdana">
<body>
<form action="userdeleted.php" method="post">
<?php
echo "<SELECT NAME=\"DelU\">";
echo "<option value>";
echo "--- Select user ---";
echo "</option>";
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("sodadb", $con);
$result = mysql_query("SELECT * FROM extensions");
while($row = mysql_fetch_array($result))
{
echo $row['ExtensionNum'] . " " . $row['ExtensionPin'] . " " . $row['ExtensionUsername'] . " " . $row['Department'] . "<BR>" ;
echo "<option value>";
echo $row['ExtensionUsername'];
echo "</option>";
}
echo "</SELECT>";
?>
<input type="submit" value="Delete User" />
</body>
</font>
</html>
You can then select a user and click "Delete User" which is a HTML form with in the PHP <PHP? ?> code.
Which directs to userdeleted.php
The userdeleted.php then post gets a variable from the form element combobox wich is called DelU.
Like so
Code: Select all
$DelUser = $_POST['DelU'];
"" so if i create a record in the table with the username field blank it deletes it so the statement works.
Something to add to the problem, the code work perfectly on my WAMP (Windows installation) but it doesnt work on
My Ubuntu Xamp installation (PHP on Xamp works as i'm using PHP admin to modify the database on ubuntu and i have one other form that is also working using a text box but in this problem its a selection or "Combo box"
Code: Select all
<html>
<font size="1" face="Verdana">
<body>
<?php
$DelUser = $_POST['DelU'];
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("sodadb", $con);
mysql_query("DELETE FROM extensions WHERE ExtensionUsername='$DelUser'");
mysql_close($con);
Echo $DelUser . " has been sucessfully deleted. <BR> <BR> ";
echo "<a href=\"usermanager.php\">Back</a>"; echo " to the user manager.";
?>
</body>
</font>
</html>