php delete database record row by link?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tenacious-dee
Forum Newbie
Posts: 19
Joined: Tue Jan 20, 2009 8:44 am

php delete database record row by link?

Post by tenacious-dee »

Hi there

I'm trying to print all of the rows from a table in my database and then provide a link after each one to link to a delete script (deleteNews1.php)

I keep getting errors with this code...


<?php

$mysqli = mysqli_connect("localhost", "root", "Dee1987!", "anml");

if(mysqli_connect_errno()){
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}else{
//Get all records in all columns from table and put it in $result.
$result=mysql_query("select * from tblnews");

/*Split records in $result by table rows and put them in $row.
Make it looping by while statement. */
while($row=mysql_fetch_assoc($result)){

// Output
echo "ID :$row['news_id'] <br/>";
echo "Name :$row['news_name']<br/>";
echo "Email :$row['news_date']<br/>";
echo "Tel :$row['news_location']<br/>";

// Add a link with a parameter(id) and it's value. This for delete record at delete.php
echo '<a href="deleteNews1.php?id='.$row['news_id'].'">Delete</a>';

}

mysql_close($mysqli);
?>

deleteNew1.php:
<?PHP
$mysqli = mysqli_connect("localhost", "root", "Dee1987!", "anml");
$time = time();
$date = date("jS F Y", $time);
$id=$_GET['id'];

if (mysqli_connect_errno()){
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}else{
$id=$_GET['id'];

// Do delete statement.
mysql_query("delete from tblnews where news_id='$id'");

// Close database connection
mysql_close();

// Redirect to deleteNews.php.
header("location:deleteNews.php"); }
?>

Any body any ideas? Much appreciated as i need to get this figured asap! :)

Thanks
Dee
mattpointblank
Forum Contributor
Posts: 304
Joined: Tue Dec 23, 2008 6:29 am

Re: php delete database record row by link?

Post by mattpointblank »

Be specific - what errors? What line(s)?

Also, use [syntax=php]php tags[/syntax] to display your code.
Post Reply