I have some code that populates a dropdown box with tshirt names and when a user selects one and clicks go, it deletes the tshirt. Is there a way to repopulate the dropdown after delete instead of refreshing the page each time?
<?php
$connection = mysql_connect("xxx","xxx","xxx") or die("No Connection");
$db = mysql_select_db("xxx", $connection) or die("No Database");
$shirtsql = "SELECT distinct shirtname from tshirts ORDER BY shirtname ASC";
$shirtsql_result = mysql_query($shirtsql,$connection)
or die("Couldn't execute query.");
while ($row = mysql_fetch_array($shirtsql_result)) {
$shirtname = $row["shirtname"];
$CatList.= "<OPTION value=\"$shirtname\">$shirtname</OPTION>";
}
?>
<?php
if ($_POST[submit])
{
$connection = mysql_connect("xxx","xxx","xxx") or die("Couldn't make connection.");
$db = mysql_select_db("xxx", $connection) or die("Couldn't select database.");
$query = "SELECT catID FROM tshirts where shirtname = '$DelShirt'";
$result = MySQL_query($query);
While( $rows = MySQL_fetch_array($result) ) {
$catid = $rows['catID'];
}
$query = "DELETE from category where catID = '$catid'";
$result = MYSQL_query($query);
$query = "DELETE from tshirts where shirtname = '$DelShirt'";
$result = MYSQL_query($query);
echo "T-Shirt Deleted";
}
?>
<form method="post" action="<?PHP echo $PHP_SELF?>">
<SELECT name="DelShirt" style="color : #ffffff; background-color : #A59ACF; font : bold; letter-spacing : 0px" size="10">
<option value=\"\" name=DelShirt>Available T-Shirts</option>";
<? echo "$CatList"; ?>
</SELECT>
<input type="Submit" name="submit" value="Go">
</form>
<br><br>
</body>
</html>