Forum Moderators: open
<?
//include our database connection file
include('dbconnect.php');if($_POST['action']=="doedit"){
//grab the post vars
$title = $_POST['title'];
$id = $_POST['id'];
$news = $_POST['news'];
//update the database
$news = "UPDATE news SET title='$title', news='$news' WHERE id = $id";
$editnews = mysql_query($news);
echo("news edited.");
}
//print the news titles, with links to the edit page
$getnews = mysql_query("select * from news ORDER BY id DESC");
while($r=mysql_fetch_array($getnews)){
extract($r);
echo("> $title<a href=editnews.php?id=$id&action=edit> Edit</a>");
echo("> <a href=editnews.php?id=$id&action=delete> Delete</a><br />");
}
echo("<br /><br />");
//if we are editing a news item, print the following..
if($_GET['action']=="edit"){
$id = $_GET['id'];
$getnews = mysql_query("select * from news WHERE id=$id");
while($r=mysql_fetch_array($getnews)){
extract($r);
//our form
//if we are deleting a news item, print the following..
if($_GET['action']=="delete"){
$query1=mysql_query("delete from news where id=$id");
mysql_query($dbname, $query1) or die("Failed Query of " . $query1);
echo("> $title . $id . ' has been deleted as requested'.<br>");
}
//our form
?>
<form action="editnews.php" method="POST">
<input type="text" name="title" value="<? echo($title); ?>" /><br />
<textarea name="news" rows="6" cols="50"><? echo($news); ?></textarea>
<input type="submit" value="edit" />
<input type="hidden" name="id" value="<? echo($id); ?>" />
<input type="hidden" name="action" value="doedit" />
</form>
<?
}
}
?>
Thanks for any help you can give.
If you are getting some type of FORIEGN KEY VIOLATION related error then more than likely the ID for the news article you are attempting to delete is also being used as a foreign key in other tables. If this is the case, you need to delete all of the rows that reference ID in other related tables before attempting to delete the row for ID from NEWS.
When I click the delete link next to the news thread I want to delete nothing happens. I refresh the page to see if the topics are gone but they are still there.