LiveWire Network Peer Answers Peer Support Teen Forums Tech Forums College Forums 320 users online 221738 members 290 active today Advertise Here Sign In
TeenCollegeTechPhotos | Quizzes | LiveSecret | Memberlist | Dictionary | News | FAQ
Member Spotlight
wickram
I haven't filled out my profile...
Mood: Musical
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
3 online / 15 MPM
Fresh Topics
  LiveWire / Technical Forums / Programming & Application Development / Viewing Topic

Update news script.
Help!
Replies: 2Last Post June 7, 2006 11:05am by PiXiE
Welcome to LiveWire!
We're Stronger Together.
Join the Community
Single page for this topic Email Print Favorite
( PiXiE )


24.24.1.1358

Patron
Reply
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?

8:53 am on June 7, 2006 | Joined: July 2002 | Days Active: 1,663
Join to learn more about PiXiE Alberta, Canada | Straight Female | Posts: 4,837 | Points: 34,868
Single page for this topic Email Print Favorite

Quick Reply

You are signed in as our guest.

Looking for something else?
 

  LiveWire / Technical Forums / Programming & Application Development / Viewing Topic