0

Hi,
could some help me . as i want to know how to delete last record.

currenlty the code im using its based on two different pages, one for update/display record and second for deleting record.
but sum reason this code not working for me .

add.php
<?php


include("connect2.php");
$authorname = trim($_POST);
$publishyear = trim($_POST);
$booktitle = trim($_POST);
$edition = trim($_POST);
$place = trim($_POST);
$publisher = trim($_POST);
// insert into table name?
$query = "INSERT INTO book (id, authorname, publishyear, booktitle, edition, place, publisher)
VALUES ('', '$authorname', '$publishyear', '$booktitle', '$edition', '$place', '$publisher')";
$results = mysql_query($query);

if ($results)
{
echo "<br/><br/>Your book reference is :<br/>";
echo "$authorname, $publishyear, $booktitle, $edition, $place, $place, $publisher ";

// delet query


echo '<a href="deleted.php?id='.$row.'">Delete</a>';

}
mysql_close();
?>


/* for delete record */

deleted.php
<?php


include("connect2.php");

$id = $_GET;

$delete = "DELETE FROM book WHERE id = '$id' ";
mysql_query($delete);
mysql_close();

echo "Entry deleted";

?>

pls help me to correct this pice of code ... or if you know any other commend for deleting last record.

thanks

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by hielo
0

...echo '<a href="deleted.php?id='.$row['id'].'">Delete</a>'; where did $row come from?
a. An INSERT query does NOT return any records - NOT even the auto id of the new record.
b. Even IF it returned records, you would still need to retrieve the actual columns with statement such as:

<?php
$row=mysql_fetch_assoc($results);
?>

but like I said, an INSERT does not return any records, so $results does NOT "point" to a recordset!

Instead what you need is mysql_insert_id():
http://us2.php.net/manual/en/function.mysql-insert-id.php

So change:

echo '<a href="deleted.php?id='.$row['id'].'">Delete</a>';

to:

echo '<a href="deleted.php?id='. mysql_insert_id() .'">Delete</a>';

Edited by hielo: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.