This is my first attempt at php coding. I managed to find a couple of tutorials that helped me set up a news section where I could update art of my website as I need to. I also managed to find another tutorial that allows me to edit the news items but what I would love is to be able to add an option to delete as well ('dodelete'?). I am totally lost and probably in over my head but you don't learn by not trying right?
Here is the code I am using for the adding / editing.
Any help would be greatly appreciated!
THANK YOU!
Code: Select all
<form action="submit.php" method="post">
<b>Title</b>
<BR />
<input type="text" name="title" size="40" maxlength="80" value="" />
<br />
<br />
<b>News</b><BR><textarea name="news" rows="3" cols="40"></textarea>
<br />
<br />
<input type="submit" value="submit" /> <input type="reset" value="reset" />
</form>
<b>EDIT NEWS</b><br>
<?
include('dbconnect.php');
if($_POST['action']=="doedit"){
$title = $_POST['title'];
$id = $_POST['id'];
$news = $_POST['news'];
$news = "UPDATE news SET title='$title', news='$news' WHERE id = $id";
$editnews = mysql_query($news);
echo("news edited.<br>");
}
$getnews = mysql_query("select * from news ORDER BY id DESC");
while($r=mysql_fetch_array($getnews)){
extract($r);
echo("> <a href=addnews.php?id=$id&action=edit>$title</a><br />");
}
echo("<br /><br />");
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
?>
<form action="addnews.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>
<?
}
}
?>