Jump to content

[SOLVED] Edit entry and overwrite existing string


FridayRain

Recommended Posts

I've accomplished half of what I want to do. I have an 'edit' link on blog entries and writing pieces for my upcoming site, and clicking it brings up the piece within a form so I can make changes. Now the only trouble is processing the form and having PHP and MySQL make the changes. I'm having trouble figuring out exactly how to replace or overwrite an entire string.

 

I came across the Locate command, but I was under the impression it was useful to search for text to replace, not necessarily (or efficient) for replacing an entire string. Also, does the fopen command work with MySQL queries?

Link to comment
Share on other sites

As previously suggested u can replace the whole text with the UPDATE command:

 

if(isset($_POST['editfield'])){
     $id = $_SESSION['id']; //just assuming
     $edit = $_POST['editfield'];
     $results = mysql_query("UPDATE table SET article='$edit' WHERE id='$id'") or die(mysql_error());
}

Link to comment
Share on other sites

What's the syntax for multiple strings possibly being replaced? I also have a title field available for edit. This is about as close as I've come:

 

<?php

$query = mysql_query("UPDATE $table SET title='$title' text='$edittext' WHERE id='$id'") or die(mysql_error());

?>

Link to comment
Share on other sites

I can't get the NOW() function to work. Each time I try, the entry gets all 0s for the datetime.

 

I Googled and apparently it's not a function of PHP, but only of MySQL. so I tried this:

 

    $query = mysql_query("INSERT INTO $table(id, title, text, date, year) VALUES ('$id', '$title', '$text', 'NOW()', '$year')") or die (mysql_error());

 

And still all 0s.

Link to comment
Share on other sites

  • 2 weeks later...

Er, one more thing. Using the DATETIME function, I'm converting the time information into a readable format to show each blog entry's time of posting. But the format is 00:00, so if the hour is one digit, the 0 appears in front of it. How can I remove the 0 from the resulting string?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.