so I’ve been trying to write a CMS for a client to update their website. I’m working on trying to get the update news script to work, and I was wondering how I could get the script to not only update the news itself but also the title. Here is the script:
PHP:
//used to get data from previous page. $previous_title was so I can use it to set the where in the update query.
if($_GET['title']) {
$title = $_GET['title'];
$previous_title = $_GET['title'];
}
if($_POST['title']) {
$title = $_POST['title'];
$news = $_POST['news'];
//used to update both news and title
mysql_query("UPDATE `News` SET `Title`='$title', `Content`='$news' WHERE `Title`='$previous_title'");
header("Location: viewNews.php");
}
HTML:
<form id = "addNews" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="hidden" name="hidden" id="hidden" value="hidden" />
<input type="text" name="title" size="68" id = "title" value="<?php echo $query['Title'];?>"/><br/><br/>
<textarea name="news" id="news"><?php echo $query['Content'];?></textarea><br />
<input type="submit" value="Update News"/>
</form>
Thanks!
In update query you are updating both of fields
Title & ContentBut if you want to update only news then your SQL like this :
You should take care of
$previous_titleBecause in this context
$previous_titlemay not available