Hi all,
I have now managed to get the script to display all records, but I can't get it to delete any records. The edit works fine but can someone show me how to add a delete button as well so that I can delete the one chosen with the current id please.
This is the code I have so far:
<?
//include our database connection file
include('dbconnect.php');
if($_POST['action']=="doedit"){
//grab the post vars
$title = $_POST['title'];
$id = $_POST['id'];
$sector = $_POST['sector'];
$location = $_POST['location'];
$salary = $_POST['salary'];
$details = $_POST['details'];
//update the database
$news = "UPDATE news SET title='$title', sector='$sector', location='$location', salary='$salary', details='$details' 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("> <a href=editjobs.php?id=$id&action=edit>$title</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
?>
<form action="editjobs.php" method="POST">
<input type="text" name="title" value="<? echo($title); ?>" /><br />
<input type="text" name="sector" value="<? echo($sector); ?>" /><br />
<input type="text" name="location" value="<? echo($location); ?>" /><br />
<input type="text" name="salary" value="<? echo($salary); ?>" /><br />
<textarea name="details" rows="6" cols="50"><? echo($details); ?></textarea>
<input type="submit" value="edit" />
<input type="hidden" name="id" value="<? echo($id); ?>" />
<input type="hidden" name="action" value="doedit" />
</form>
<?
}
}
?>