Im sure this has been posted a billion times, but ive followed steps on other threads and still no look. What im wanting to do is to be able to delete a record from a form that is echoed..get me?
Heres the steps:
- Post update news, insterts it into database
- Reloads page and fetches the update news
- Echoes it into a table and also echoes a delete button wrapped in a form tag
- When you press the delete button, it deletes that record only
Here is the code i have for echoing the update news:
$select_updates=mysql_query("SELECT * FROM resource ORDER BY id DESC");
while($the=mysql_fetch_object($select_updates)){
echo " <FORM action='delrec.php?id='. mysql_insert_id() .'' method='post' <table width='263' border='1' align='center' cellpadding='0' cellspacing='0' bordercolor='#000000'>
<tr>
<th colspan='2' bgcolor='#990033' scope='col'>$the->linkname</th>
</tr>
<tr>
<td width='65'>Info</td>
<td width='192'>$the->info</td>
</tr>
<tr>
<td>link to site</td>
<td><a href=http://$the->link>$the->linkname</a></td>
</tr>
<tr>
<td>ID: $the->id</td>
<td><input type='submit' name='delred' id='delred' value='Delete'></td>
</tr>
</table></form><BR>";
}
That works fine, it sends into to the delrec.php file.
Heres the delrec.php file:
<?php
session_start();
$plod=mysql_connect("localhost","razorsh1","********");
if (!$plod)
{
die('Could not connect: ' . mysql_error());
}
$id = $_GET['id'];
$delete = "DELETE FROM resource WHERE id = '$id' ";
mysql_query($delete);
echo "Deleted...Redirecting";
mysql_close($plod);
?>
<head>
<meta http-equiv="refresh" content="1; URL=test.php">
</head>
Once its pressed, it is saying Deleted...Redirecting like it should if it had deleted the piece of news, but when it redirects to the page, that update news is still there and it hasnt been deleted.
Where am i going wrong? Id be really grateful