Update issue

Hey guys i’m having a problem with my UPDATE, I can get the values to display, however when pressing the Edit button on my form it doesn’t update. Here is my code.

[php]if (isset($_GET[‘newsid’])){
$newsid = $_GET[‘newsid’];
if (is_numeric($newsid)){
$result = mysql_query(“select title, content, date, author from news where newsid = ‘$newsid’”) or die (mysql_error());
$row = mysql_fetch_object($result);

	echo '<form action="editnews.php" method="post">
	<label for="title">Title</label><br/>
	<input type="text" name="title" value="'.$row->title. '" /><br/><br/>

	<label for="content">Content</label><br/>
	<textarea name="content"> '.$row->content. ' </textarea>
	<input type="hidden" name="id" value="'.$newsid.'" /><br/><br/>
	
	<label for="title">Date</label><br/>
	<input type="text" name="date" value="'.$row->date.'" /><br/><br/>
	
	<label for="title">Author</label><br/>
	<input type="text" name="date" value="'.$row->author.'" /><br/><br/>
	
	<input type="submit" value="Edit"/>
	</form>';
}

}

if (!empty($_POST[‘title’]) && !empty($_POST[‘content’]) && !empty($_POST[‘date’]) && !empty($_POST[‘author’])) {

$title = $_POST['title'];
$content = $_POST['content'];
$date = $_POST['date'];
$author = $_POST['author'];
$newsid = $_POST['newsid'];
$title = mysql_real_escape_string($title);
$content = mysql_real_escape_string($content);
$date = mysql_real_escape_string($date);
$author = mysql_real_escape_string($author);

mysql_query("UPDATE news SET title='$title' , content='$content' , date='$date' , author='$author' WHERE newsid='$newsid'") or die (mysql_error());
echo '<h2>Noticed edited</h2>';

}

$result = mysql_query(“select * from news”) or die (mysql_error());

while ($row = mysql_fetch_object($result)){

echo $row->title;
echo ' <a href="editnews.php?newsid='.$row->newsid.'"> Edit this notice.</a> <br/><br/> ';

}

?>[/php]

Thanks

What error are you getting? Thanks.

the problem is because you wrote for it to only update if post title, post content, post date and post author are not empty but in your form, you made a mistake and where it should be post author it is:
[php]name=“date” value="’.$row->author.’" /><
[/php]

you accidentally named it date instead of author

Sponsor our Newsletter | Privacy Policy | Terms of Service