Jump to content

How easy is it to add a delete function


sdm

Recommended Posts

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>

<?

 

}

}

?>

Link to comment
https://forums.phpfreaks.com/topic/40938-how-easy-is-it-to-add-a-delete-function/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.