I am trying to build a news page. I can add news, but if I try to edit it It won't display the body in the box or update any of it. Any help
<html>
<body>
<?php
$db = mysql_connect("localhost", "electric_em", "hiron9r");
mysql_select_db("electric_emnews",$db);
if ($submit) {
// here if no ID then adding else we're editing
if ($news_id) {
$date = date("Y-m-d");
$sql = "UPDATE news SET heading='$heading',
body='$body',date=$date,auth='$auth',auth_email='$auth_email'
WHERE news_id=$news_id";
} else {
$date = date("Y-m-d");
$sql = "INSERT INTO news
VALUES (NULL,'$heading','$body',
'$date','$auth','$auth_email')";
}
// run SQL against the DB
$result = mysql_query($sql);
echo "Record updated/edited!<p>";
?>
<a href="admin_news_index.php"> Return to News editing </a>
<?
} elseif ($delete) {
// delete a record
$sql = "DELETE FROM news WHERE news_id=$news_id";
$result = mysql_query($sql);
echo "Record deleted!<p>";
?>
<a href="admin_news_index.php"> Return to News editing </a>
<?
} else {
// this part happens if we don't press submit
?>
<P>
<?
if (!$edit_news && !$add_news) {
print("<a href=\"admin_news_index.php?add_news=yes\">ADD NEWS</a>");
?>
<h3>Or select one to edit:</h3>
<?php
}
if ($add_news) {
print("<h3>Add your news</h3>");
}
if ($edit_news) {
print("<h3>Edit news story</h3>");
}
?>
<P>
<form method="get" action="admin_news_index.php">
<?php
if (!$news_id && !$add_news) {
// print the list if there is not editing
$result = mysql_query("SELECT * FROM news",$db);
while ($row = mysql_fetch_array($result)) {
?>
<table border="1" cellpadding="3">
<?php
print("<tr><td bgcolor=\"#e5e5e5\"><b>");
printf("<font color=\"Black\">%s</font></b></td></tr>\n",
$row["heading"]);
printf("<td>By: <a href=\"mailto:%s\">%s</a>\n",
$row["author_email"], $row["author_name"]);
printf("<br>Posted: %s<hr>\n",
$row["date"]);
printf("%s</td></tr>\n",
$row["body"]);
print("<tr align=\"right\"><td>");
printf("<a href=\"admin_news_index.php?news_id=%s&edit_news=yes\">(EDIT)</a>", $row["news_id"]);
print(" ");
printf("<a href=\"admin_news_index.php?news_id=%s&delete=yes\">(DELETE)</a><br><br>", $row["news_id"]);
print("</td></tr>");
print("</table>");
}
}
if ($news_id) {
// editing so select a record
$sql = "SELECT * FROM news WHERE news_id=$news_id";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$news_id = $row["news_id"];
$heading = $row["heading"];
$auth = $row["author_name"];
$auth_email = $row["author_email"];
$body = $row["body"];
$date = $row["date"];
//print the id for editing
?>
<input type=hidden name="news_id" value="<?php echo $news_id ?>">
<?php
}
?>
<?php
if ($edit_news || $add_news) {
?>
Name:<br><input type="Text" name="auth" value="<? echo $auth; ?>"><p>
Email:<br><input type="Text" name="auth_email" value="<? echo $auth_email; ?>"><p>
Heading:<br><input type="Text" name="heading" value="<? echo $heading; ?>"><p>
News:<br><textarea cols=40 rows=20 name="body" value="<? echo $body; ?>"</textarea><p>
<input type="Submit" name="submit" value="Submit!">
</form>
<?php
}
}
?>
I also know I should be doing POST and $_POST, but i am trying to see the values I am passing.