Cleaning up code with IF ?
Posted: Tue Oct 07, 2003 9:15 am
Deletenews.php file
Delete.php file
Can someone help me combine these two file into one so that when I delete the record it returns to the initial view / delete section.
Thanks.
Code: Select all
<?php
$relative_script_path = '.';
include("$relative_script_path/config/config.php");
$connection = mysql_connect($DBHOST,$DBUSER)
or die("Connection unsuccessful: " . mysql_error());
mysql_select_db($DBASE)
or die("Connection to database unsuccessful: " . mysql_error());
$sql = "SELECT * FROM news_table";
$result = mysql_query($sql,$connection);
echo "<TABLE BORDER=2 align=center width=472>";
echo"<TR><TD><B>Title</B></TD><TD><B>Author</B></TD><TD><B>Short Story</B></TD></TR>";
while ($row = mysql_fetch_array($result))
{
echo "<TR><TD>".$row["title"]."<br />".$row["author"]."</TD>";
echo "<TD><a href="viewnews.php?id=".$row[id]."">View</a> ";
echo "<a href="delete.php?id=".$row[id]."">Delete</a></TD>";
echo "<TD>".$row["shortstory"]."</TD></TR>";
}
echo "</TABLE>";
mysql_close($connection);
?>Code: Select all
<?php
$relative_script_path = '.';
include("$relative_script_path/config/config.php");
$connection = mysql_connect($DBHOST,$DBUSER)
or die("Connection unsuccessful: " . mysql_error());
mysql_select_db($DBASE)
or die("Connection to database unsuccessful: " . mysql_error());
$sql = "DELETE FROM news_table WHERE id=$id";
mysql_query($sql,$connection) or die("Message could not be deleted: " . mysql_error());
echo("Your selected row was successfully deleted. Thank you.<br /><br />");
mysql_close($connection);
?>Thanks.