You will have to view the source...or view below:
NEWSINPUT
<body>
<?php
$db = mysql_connect("localhost", "USERNAME", "PASS");
mysql_select_db("frankdb",$db);
if ($submit) {
// here if no id then adding else we're editing
if ($id) {
$sql = "UPDATE news SET title='$title',date='$date',byline='$byline',story='$story',viewed='$viewed' WHERE id=$id";
} else {
$sql = "INSERT INTO news (title,date,byline,story,viewed) VALUES ('$title','$date','$byline','$story','$viewed')";
}
// run SQL against the DB
$result = mysql_query($sql);
echo "Record updated/edited!<p><a href=newsedit.php3>Return</A>";
} elseif ($delete) {
// delete a record
$sql = "DELETE FROM news WHERE id=$id";
$result = mysql_query($sql);
echo "$sql Record deleted!<p><a href=newsedit.php3>Return</A>";
} else {
// this part happens if we don't press submit
if (!$id) {
// print the list if there is not editing
$result = mysql_query("SELECT * FROM news",$db);
echo "<h2>News Stories </h2>Pressing DELETE is final, and recovery is NOT available!<br>
Click the TITLE of the news story to edit the information. To have this story appear on the main page, enter \"Yes\" in the Viewable field at the bottom.<P><TABLE width=100%><TR><TD><B>TITLE</B></TD><TD><B>DATE</B></TD><TD><B>VIEWABLE</B></TD><TD><B>DELETE!</B></TD></TR>";
while ($myrow = mysql_fetch_array($result)) {
printf("<tr><td><a href=\"%s?id=%s\"><B>%s</B></a></td><td>%s</td><td><center>%s</center></td> \n", $PHP_SELF, $myrow["id"], $myrow["title"], $myrow["date"], $myrow["viewed"]);
printf("<td><a href=\"%s?id=%s&delete=yes\">(DELETE)</a></td></tr>", $PHP_SELF, $myrow["id"]);
}
}
?>
</table><P>
<a href="<?php echo $PHP_SELF?>">RETURN TO LIST</a>
<P>
<form method="post" action="<?php echo $PHP_SELF?>">
<?php
if ($id) {
// editing so select a record
$sql = "SELECT * FROM news WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
$id = $myrow["id"];
$title = $myrow["title"];
$date = $myrow["date"];
$byline = $myrow["byline"];
$story = $myrow["story"];
$viewed = $myrow["viewed"];
// print the id for editing
?>
<input type=hidden name="id" value="<?php echo $id ?>">
<?php
}
?><table border=0>
<tr><td>Title:</td><td><input size="60" type="Text" name="title" value="<?php echo $title ?>"></td>
<tr><td>Date:</td><td><input size="15" type="Text" name="date" value="<?php echo $date ?>"></td>
<tr><td>By:</td><td><input size="30" type="Text" name="byline" value="<?php echo $byline ?>"></td>
<tr><td>Story:</td><td colspan=3><textarea cols="60" rows="10" wrap="soft" name="story"><?php echo $story ?></textarea></td></tr>
<tr><td>Viewable:</td><td><input type="Text" name="viewed" value="<?php echo $viewed ?>"></td>
</table>
<input type="Submit" name="submit" value="Enter information">
</form>
<?php
}
?>
</body>
NEWSOUTPUT
<body>
<?php
$db = mysql_connect("localhost", "USERNAME", "PASS");
mysql_select_db("frankdb",$db);
$result = mysql_query("SELECT * FROM news WHERE viewed='Yes' ORDER BY id DESC",$db);
if ($myrow = mysql_fetch_array($result)) {
echo "<table border=1>\n";
do {
printf("<tr><td>%s<br>%s %s</td></tr><tr><td>%s</tr>\n", $myrow["title"], $myrow["date"], $myrow["byline"], $myrow["story"]);
} while ($myrow = mysql_fetch_array($result));
echo "</table>\n";
} else {
echo "Sorry, no records were found!";
}
?>
</body>