Code: Select all
if(isset($_GET['pid']) )
{
$id = $_GET['pid'];
$sql = "DELETE FROM post WHERE is $_GET[id]";
$result = mysql_query($sql) or die ("Failed".mysql_error());
}
This is my blog code
Code: Select all
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1>The last 5 added posts</h1>
<a href='member.php'>Return to profile</a><br>
<ul>
<?php
if (!$link = mysql_connect('igor.gold.ac.uk', 'ma301sl', 'fitnesspal1')) {
echo 'Could not connect to mysql';
exit;
}
if (!mysql_select_db('ma301sl_blog', $link)) {
echo 'Could not select database';
exit;
}
$sql = 'SELECT * FROM post ORDER BY id DESC LIMIT 10';
$result = mysql_query($sql, $link);
if (!$result) {
echo "DB Error, could not query the database\n";
echo 'MySQL Error: ' . mysql_error();
exit;
}
while ($row = mysql_fetch_assoc($result)) {
$id=$row['id'];
$title=$row['title'];
$creator=$row['creator'];
$body=$row['body'];
$date=$row['date'];
$menu = "<li><a href=?pid=$id>$title</a></li>";
echo $menu;
}
mysql_free_result($result);
?>
<?php
if (!$link = mysql_connect('igor.gold.ac.uk', 'ma301sl', 'fitnesspal1')) {
echo 'Could not connect to mysql';
exit;
}
if (!mysql_select_db('ma301sl_blog', $link)) {
echo 'Could not select database';
exit;
}
$pid = $_GET['pid'];
$sql = "SELECT * FROM post WHERE id=$pid" ;
$result = mysql_query($sql, $link);
if (!$result) {
echo "DB Error, could not query the database\n";
echo 'MySQL Error: ' . mysql_error();
exit;
}
while ($row = mysql_fetch_assoc($result)) {
$id=$row['id'];
$title=$row['title'];
$creator=$row['creator'];
$body=$row['body'];
$date=$row['date'];
$post = "<h1>$title</h1><p>$creator</p><p>$body</p><p>Posted on : $date</p>";
echo $post;
echo "<a href=\"edit.php?id=" . $id=$row['id'] . "\">Edit</a>";
echo "<span> </span>";
echo "<a href=\"delete.php?id=" . $id=$row['id'] . "\">Delete</a>";
}
mysql_free_result($result);
?>
<ul/>
</td>
</body>
</html>