LiveWire Network Peer Answers Peer Support Teen Forums Tech Forums College Forums 469 users online 224839 members 593 active today Advertise Here Sign In
TeenCollegeTechPhotos | Quizzes | LiveSecret | Memberlist | Dictionary | News | FAQ
Member Spotlight
ItsEllaYeah
Cool Things: I'm cooler than everything
Mood: Confused
You have 1 new message.
Emergency Help
Until you sign up you can't do much. Yes, it's free.

Sign Up Now
Membername:
Password:
Already have an account?
Invite Friends
Active Members
Groups
Contests
Moderators
4 online / 25 MPM
Fresh Topics
  LiveWire / Technical Forums / Programming & Application Development / Adding Reply

Adding Reply
Archived Topic: It will not be bumped to the top of the forum.
Topic Update news script.
Membername   Not a member? Sign Up Free (takes 20 seconds)
Password   Forgotten your password?
Post

Font:   Size:   Color:

FAQ Keyword Search:
Post Options
Favorites Manager
Notify me of new replies to this topic by email
Notify me of new replies to this topic by private message
Original Post
PiXiE Posted at 8:53 am on June 7, 2006
Here is the problem. I have a news page. The news entries come from a database. I have no problem inserting new news entries. I'm trying to write code that will edit existing entries. Here is the code (minus the database connection/header stuff):
Code:

<?php if (isset($_POST['submit'])){
$myUpdate = "UPDATE news SET news_title = '$news_title', news_posted_by='$news_posted_by', news_content= '$news_content' WHERE news_id = '".$news_id."'";
$result = mysql_query($myUpdate);
if (!$result) {
echo "There was a problem. Please try again.";
} else {
echo "You have updated successfully.";
}
} else {

?>
<div>

<form name="form1" method="post" action="news_edithandler2.php?id=<?php echo $news_id ?>">
<div class="label">Title: </div> <div class="input"><input name="news_title" type="text" id="news_title" value="<?php echo $row_myrecord['news_title'] ?>"></div>
<div class="label">Posted By: </div> <div class="input"><input name="news_posted_by" type="text" id="news_posted_by" value="<?php echo $row_myrecord['news_posted_by']; ?>"></div>
<div class="label">Body: </div> <div class="input"><textarea name="news_content" cols="60" rows="10" id="news_content"><?php echo stripslashes($row_myrecord['news_content']); ?></textarea></div>
<div class="input"><input name="submit" type="submit" value="submit" /></div>
</form>
</div>
<?php } ?>


When you first hit the edit button, the current values in the database show up fine in this form. Once I edit the entries and hit submit, "You have updated successfully" is displayed. The weird part is that the database doesn't get updated, but it erases whatever was there before!! What is going on?

Replies
PiXiE Posted at 8:53 am on June 7, 2006
Here is the problem. I have a news page. The news entries come from a database. I have no problem inserting new news entries. I'm trying to write code that will edit existing entries. Here is the code (minus the database connection/header stuff):
Code:

<?php if (isset($_POST['submit'])){
$myUpdate = "UPDATE news SET news_title = '$news_title', news_posted_by='$news_posted_by', news_content= '$news_content' WHERE news_id = '".$news_id."'";
$result = mysql_query($myUpdate);
if (!$result) {
echo "There was a problem. Please try again.";
} else {
echo "You have updated successfully.";
}
} else {

?>
<div>

<form name="form1" method="post" action="news_edithandler2.php?id=<?php echo $news_id ?>">
<div class="label">Title: </div> <div class="input"><input name="news_title" type="text" id="news_title" value="<?php echo $row_myrecord['news_title'] ?>"></div>
<div class="label">Posted By: </div> <div class="input"><input name="news_posted_by" type="text" id="news_posted_by" value="<?php echo $row_myrecord['news_posted_by']; ?>"></div>
<div class="label">Body: </div> <div class="input"><textarea name="news_content" cols="60" rows="10" id="news_content"><?php echo stripslashes($row_myrecord['news_content']); ?></textarea></div>
<div class="input"><input name="submit" type="submit" value="submit" /></div>
</form>
</div>
<?php } ?>


When you first hit the edit button, the current values in the database show up fine in this form. Once I edit the entries and hit submit, "You have updated successfully" is displayed. The weird part is that the database doesn't get updated, but it erases whatever was there before!! What is going on?
All 2 previous replies displayed.