Hello. I'm having trouble with this (that puts it lightly... I'm about to rip my hair out) and wonder if anybody can help me out.
What I would like to see is the form used to edit a given record to be replaced by a query of the same id, which shows exactly how the updated info will look to the public.
What is happening currently with the page is that the person updates the record using the form you see here, hits UPDATE and the form stays on the page with the display of the new information underneath it. I would simply like to replace the form entirely with that which shows up in the function added().
Does that make sense? If so, can you help? Thanks, in advance!
<?
// get ID for edit
$id = $_GET['id'];
mysql_connect("...", "...", "...") or die(mysql_error());
mysql_select_db("...") or die(mysql_error());
$query = "SELECT * FROM table WHERE id='$id'";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
// get information for edit
$i=0;
while ($i < $num) {
$id=mysql_result($result,$i,"id");
et cetera...
echo "
<p align='center'><a href='adminpanel.php'>Return to Admin Panel</a></p>
<form action='' method= 'post'>
<table width='90%' border='0' align='center' style='margin-bottom:15px;'>
et cetera...
<tr>
<td colspan='8' align='right'><input type='submit' name='ud_update' value='Update'></td>
</tr>
</table>
</form>";
$i++ ;
}
$ud_id = $_POST['ud_id'];
et cetera...
function added(){
$id = $_GET['id'];
mysql_connect("...","...","...");
mysql_select_db("...") or die("Unable to select database");
$query = "SELECT * from table where id = $id";
$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);
$result = mysql_query($query) or die("Couldn't execute query");
$a = $numrows;
while ($row= mysql_fetch_array($result)) {
$id = $row["id"];
et cetera...
echo "
<table width='600px' align='center' style='border: 1px solid #ccc; background-color: #fff; padding: 3px 3px 3px 5px;'>
<tr>
<td colspan='3' valign='top'><b>Admin</b>: (<a href=\"edit.php?id=$id\">EDIT</a> - <a href=\"del.php?id=$id\">DELETE</a>)
</tr>
</table>
<br>";
}
}
if ($ud_update){
global $id;
mysql_connect("...", "...", "...") or die(mysql_error());
mysql_select_db("...") or die(mysql_error());
$query = "UPDATE table SET ... WHERE id='$id'";
$result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);
mysql_query($query);
mysql_close();
}
if (isset($ud_update)){
added();
}
?>