Okay, I have a post news script that I made. However I wish to be able to delete the news with a link at the bottom of each one. So I made this script and it worked, but it worked wrong. It will only delete the FIRST news that is posted. None other. I have the an ID table in the DB set to int 11, auto_inc and such, so I dont think that is wrong.
But when I delete it will only delete the FIRST news. I also have an edit script that will only EDIT the first news posted.
Here is my script, and if you can tell me whats wrong, it would be appriciated. Thanks.
<?include "header.phtml"?>
<?php
// Create Connection
$connection = mysql_connect("localhost","USERNAME","PASSWORD") or die ("Couldn't Connect to Server");
// Select Database
$db = mysql_select_db("hb", $connection) or die ("Couldn't Connect to DB");
// Create SQL Statement
$sql = "SELECT name, date, title, story, id FROM Stories order by date desc" or die ("Couldn't SQL");
// Execute Search and Result
$sql_result = mysql_query($sql, $connection) or die ("Couldn't execute query");
// Start Results Formatting
// echo "<TABLE bgcolor=black BORDER = 0 WIDTH=100%>";
// Format Results
while ($row = mysql_fetch_array($sql_result) ) {
$name = $row[name];
$title = $row[title];
$story = $row[story];
$date = date("D F, Y",$row[date]);
$id = $row[id];
echo <<<EOT
<b>User:</b> $name
<br><b>Date:</b> $date<br>
<b>Title:</b> $title
<br>
<b>Journal Entry from:</b> $name<br><br>$story<br><a href=indexnewsdelete.phtml?B=C&id=$id>Delete</a><hr width=\"100%\" size=\"1\" color=\"#3B6A8A\"><br>
</font>
</center>
EOT;
}
// Close Formatting
If($B == "C") {
$sql2 = mysql_query( "DELETE FROM news WHERE id = '$id'");
}
?>
<?include "footer.phtml"?>