I'm trying to setup an admin page for a website. So far, I have it so you select what you want to view/edit and then you can search for the name. Then it brings up the requested information. The problem I'm having is that every time you update or delete something in the table that pops up after you make a search, it disappears. I would like to make it so when you update or delete something, you still see the table with the requested information without having to re-type it in. There's multiple sections to this code, but this is only one section.
<?php
mysql_connect(localhost, "---", "---");
@mysql_select_db(admin) or die("Unable to connect to database.");
//Update Section
if (isset($_POST['update']))
{
if(!empty($_POST['quanity']))
{
foreach($_POST['quanity'] as $id=>$quanity)
{
$update = "UPDATE `test` SET `quanity` = '$quanity' WHERE `id`='$id' ";
@mysql_query($update);
}
}
}
//Delete Section
if (isset($_POST['delete']))
{
if (isset($_POST['del']))
{
$dele = $_POST['del'];
foreach ($dele as $value )
{
$del = "DELETE FROM test WHERE id = $value";
$de = mysql_query($del);
}
echo "Entry Deleted";
}else
{
echo "No data selected.";
}
}
?>
<html>
<head>
</head>
<body>
<form method='POST'>
<div style="float:left; border:1px; border-style:solid; width:250px">
<b>Name Search</b><br/><input type="text" name="name_search" />
<br/>
<br/>
<b> Select what you want to edit </b>
<select name="edit_table">
<option value="test"> test
</select>
<input type ="submit" name="search" value ="Search" />
</div>
</form>
<div style ="float: right;" > <!--RIGHT SIDE-->
<?php
if (isset($_POST["search"]))
{
mysql_connect(localhost, "---", "---");
@mysql_select_db(admin) or die("Unable to connect to database.");
$name_search = $_POST["name_search"];
$edit_table = $_POST["edit_table"];
if($edit_table == "test")
{
if(!$name_search)
{
echo "Please type in a name to search for" ;
}
else{
$query = "select * from test where uname = '$name_search'";
$result=mysql_query($query);
?>
<form method="post">
<table border=1px>
<?php
while(list($uname, $id, $name, $description, $price, $quanity)=mysql_fetch_array($result))
{
?>
<th>Name</th>
<th>Description</th>
<th>Price</th>
<th>Quanity</th>
<th>Delete</th>
<tr>
<td> <?php echo $name?> </td>
<td> <?php echo $description?> </td>
<td> $<?php echo $price?> </td>
<td><input type ="text" name="quanity[<?php echo $id ?>]" value="<? echo $quanity?>" /> </td>
<td> <input type="checkbox" name="del[]" value="<?php echo $id ?>"> </td>
</tr>
<?php } ?>
</table>
<input type ="submit" name="update" value ="Update" />
<input type="submit" value="Delete Checked" name="delete" />
<br/><br/><br/>
</form>
<?php
}
}
?>
</div>
</body>
</html>
<?php } ?>