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!
I have table that shows the informations from database "MySQL", I need to add a delete link that when I click delete, the Name, News and Date will delete from the table and database. The file that I use to read the informations from database:
That would pass the value of your subject if that is your subject row to a delete page where you could run your mysql delete script. Just be sure to look for that value on the next page with something like this
On the delete page
if (isset($_GET['subject'])) {
$subject = $_GET['subject'];
}
You helped me to much. But now I have another problem that I had before.
I want that when I click Delete in that page I want to display just the message "News Deleted" not and the table. I'm using the same file for displaying the table and for deleting row. Here viewtopic.php?f=1&t=96918 php_east told me how to do that in another file but now I don't know how to do it in this file:
# if (isset($id))
# {
# mysql_query("DELETE FROM lajmet WHERE id='$id'");
# echo "News deleted!";
# }
This could potentially cause issues if the url does not contain the value id. You can eliminate that problem by placing that line within the if isset condition. And also for it to display the table only when your not deleting you'd probably want to wrap that inside the same condition. So something like this.
if (!$lidhja)
{
die('Nuk Mund Të Konektohet: ' . mysql_error());
}
mysql_select_db("$databaza", $lidhja);
if (isset($_GET['id'])){
$id = $_GET['id']
mysql_query("DELETE FROM lajmet WHERE id='$id'");
echo "News deleted!";
}else {
$result = mysql_query("SELECT * FROM lajmet ORDER BY ora DESC");
echo "<table border='1'>
<tr>
<th>Emri</th>
<th>Lajmi</th>
<th>Data&Ora</th>
<th>Delete</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['emri'] . "</td>";
echo "<td>" . $row['lajmi'] . "</td>";
echo "<td>" . $row['ora'] . "</td>";
echo "<td><a href=lexo.php?id=" . $row['id'] . ">Delete</a></td>";
echo "</tr>";
}
echo "</table>";
}
I would highly recommend having your delete script on a separate page for better security reasons and to avoid accidental deletion. But if you wish to keep it on the page you probably would want to add some sort of confirmation before deleting and also some authentication checking to avoid bots accidentally deleting as well. Hope that helps point you in the right direction.