Hi there! I´m new to php and I´m trying to create a blog from a brief tutorial. And it seems like I can´t get the posts to delete in the database. I´ve been trying to look for errors for the last couple of hours. I just get back to the blog.php file and nothing is removed. I removed the “delete-link” in post.php cause I´m not sure how to type it correctly anyway :-[ Can you help me? /Cat
post.php (sorry if html-code aren´t supposed to go in here)
[php]<?php
include(“connect.php”);
mysql_connect(“localhost”, “root”, “”);
mysql_select_db(“blog”);
$postid = (int)trim($_GET[‘post’]);
$sql = "SELECT posts.ID as ID
,
users.postname as postname
,
posts.title as title
,
posts.content as content
,
posts.date as date
FROM posts
INNER JOIN users
ON users.ID = posts.username
WHERE posts.ID = $postid
ORDER BY date DESC";
$result = mysql_query($sql);
$postdata = array();
while($row=mysql_fetch_array($result)){
$postdata = $row;
}
?>
<?php echo '<?xml version="1.0" encoding="UTF-8"?>';?>
Blog title -> <?php echo htmlentities($postdata['title']); ?>Edit
</div>
</div>
[/php]
delete: [php]<?php
include(‘connect.php’);
$conn = mysql_connect(“localhost”,“root”,"");
if (!$conn)
{
die('Could not connect to the database: ’ . mysql_error());
}
mysql_select_db(“blog”, $conn);
if (isset($_GET[‘id’]) && is_numeric($_GET[‘id’]))
{
$id = $_GET[‘id’];
$result = mysql_query(“DELETE FROM posts WHERE id= ‘$id’”)
or die(mysql_error());
// redirect back to the view page
header(“Location: blog.php”);
}
else
// if id isn’t set, or isn’t valid, redirect back to view page
{
header(“Location: blog.php”);
}
?>[/php]