I knew it was too good to be true. So I am still getting the error... but I got the form to display and populate.
Error:
Notice: Undefined index: story_id in D:\wamp\www\Superman\edit_news.php on line 17
I split the code into two pages.
edit_news.php and edit_news_submitted.php
I tried to submit the changes to the form even with the error being displayed and it did not update the record as I knew it wouldn't.
Here is the code edit_news.php: I omitted the html table code for easier reading
<?php error_reporting(E_ALL); ?>
<html>
<head>
<title>ADMIN: Edit News</title>
<style type="text/css">
<!--
body,td,th {
font-family: Arial, Helvetica, sans-serif;
}
.style3 {font-size: 12px}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
<body>
<?php
if(isset($_POST) && !empty($_POST)){ $story_id = $_POST['story_id']; }
require ('get_connected.php');
$query = "SELECT * FROM news WHERE story_id='2'";
$result = mysql_query($query);
$num = mysql_num_rows($result);
$i = 0;
while ($i<$num) {
$title = mysql_result($result, $i, 'title');
$body = mysql_result($result, $i, 'body');
$story_date = mysql_result($result, $i, 'story_date');
$author = mysql_result($result, $i, 'author');
$image = mysql_result($result, $i, 'image');
$image_text = mysql_result($result, $i, 'image_text');
$source = mysql_result($result, $i, 'source');
?>
<form action="edit_news_submitted.php" method="post">
<?php include ('header.html'); ?>
<input type="hidden" name="ud_story_id" value="<?php echo $story_id; ?>">
<input name="ud_title" type="text" value="<?php echo $title; ?>
<textarea name="ud_body" rows="15" cols="60" ><?php echo $body; ?>
<input type="text" name="ud_story_date" value="<?php echo $story_date; ?>">
<input type="text" name="ud_author" value="<?php echo $author; ?>">
<input name="ud_image" type="text" value="<?php echo $image; ?>">
<input name="ud_image_text" type="text" value="<?php echo $image_text; ?>">
<input type="text" name="ud_source" value="<?php echo $source ?>">
<br><input type="submit" value="Update"><br>
No Preview is given when "Updating" a News Story. You should verifiy the changes are correct.
</form>
<?php
++$i;
}
?>
</body>
</html>
Here is the code for edit news submitted:
<?php error_reporting(E_ALL); ?>
<html>
<head>
<title>ADMIN: Edit News</title>
<?php
if (isset($_POST)) {
$ud_story_id = isset($_POST['ud_story_id']) ? $_POST['ud_story_id'] : '';
$ud_title = isset($_POST['ud_title']) ? $_POST['ud_title'] : '';
$ud_body = isset($_POST['ud_body']) ? $_POST['ud_body'] : '';
$ud_story_date = isset($_POST['ud_story_date']) ? $_POST['ud_story_date'] : '';
$ud_author = isset($_POST['ud_author']) ? $_POST['ud_author'] : '';
$ud_image = isset($_POST['ud_image']) ? $_POST['ud_image'] : '';
$ud_source = isset($_POST['ud_source']) ? $_POST['ud_source'] : '';
$ud_image_text = isset($_POST['ud_image_text']) ? $_POST['ud_image_text'] : '';
require ('get_connected.php');
$query = "UPDATE news SET title = '$ud_title', body = '$ud_body', story_date = '$ud_story_date', author = '$ud_author', image = '$ud_image', source = '$ud_source', image_text = '$ud_image_text' WHERE story_id = '$ud_story_id'";
mysql_query($query) OR die(mysql_error());
echo "Thank you";
}
?>
</body>
</html>
I have been scratching my head for hours on this one. Can anyone suggest a remedy? Thanks.[/code]