FridayRain Posted September 7, 2007 Share Posted September 7, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/68379-solved-edit-entry-and-overwrite-existing-string/ Share on other sites More sharing options...
effigy Posted September 7, 2007 Share Posted September 7, 2007 Why not replace the whole record/field? Quote Link to comment https://forums.phpfreaks.com/topic/68379-solved-edit-entry-and-overwrite-existing-string/#findComment-343792 Share on other sites More sharing options...
Fadion Posted September 7, 2007 Share Posted September 7, 2007 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()); } Quote Link to comment https://forums.phpfreaks.com/topic/68379-solved-edit-entry-and-overwrite-existing-string/#findComment-343795 Share on other sites More sharing options...
FridayRain Posted September 7, 2007 Author Share Posted September 7, 2007 Ah, the update command. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/68379-solved-edit-entry-and-overwrite-existing-string/#findComment-343828 Share on other sites More sharing options...
FridayRain Posted September 7, 2007 Author Share Posted September 7, 2007 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()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/68379-solved-edit-entry-and-overwrite-existing-string/#findComment-344040 Share on other sites More sharing options...
lemmin Posted September 7, 2007 Share Posted September 7, 2007 Here is the documenation for UPDATE: http://dev.mysql.com/doc/refman/5.1/en/update.html Quote Link to comment https://forums.phpfreaks.com/topic/68379-solved-edit-entry-and-overwrite-existing-string/#findComment-344042 Share on other sites More sharing options...
roopurt18 Posted September 7, 2007 Share Posted September 7, 2007 From the MySQL documentation: http://dev.mysql.com/doc/refman/5.0/en/update.html UPDATE [LOW_PRIORITY] [iGNORE] tbl_name SET col_name1=expr1 [, col_name2=expr2 ...] [WHERE where_condition] [ORDER BY ...] [LIMIT row_count] (Note the comma!) Quote Link to comment https://forums.phpfreaks.com/topic/68379-solved-edit-entry-and-overwrite-existing-string/#findComment-344043 Share on other sites More sharing options...
FridayRain Posted September 8, 2007 Author Share Posted September 8, 2007 Sweet. I seem to have gotten it to work, but how do I update the entry without changing the timestamp? Quote Link to comment https://forums.phpfreaks.com/topic/68379-solved-edit-entry-and-overwrite-existing-string/#findComment-344079 Share on other sites More sharing options...
FridayRain Posted September 8, 2007 Author Share Posted September 8, 2007 Nevermind. I just pulled the original timestamp and put it into a variable. Quote Link to comment https://forums.phpfreaks.com/topic/68379-solved-edit-entry-and-overwrite-existing-string/#findComment-344085 Share on other sites More sharing options...
FridayRain Posted September 8, 2007 Author Share Posted September 8, 2007 Although, is there a more automatic way to prevent it from auto-updating? Quote Link to comment https://forums.phpfreaks.com/topic/68379-solved-edit-entry-and-overwrite-existing-string/#findComment-344090 Share on other sites More sharing options...
effigy Posted September 8, 2007 Share Posted September 8, 2007 Yes. 1. Don't use TIMESTAMP, use DATETIME. 2. Read more about TIMESTAMP. Quote Link to comment https://forums.phpfreaks.com/topic/68379-solved-edit-entry-and-overwrite-existing-string/#findComment-344101 Share on other sites More sharing options...
FridayRain Posted September 8, 2007 Author Share Posted September 8, 2007 Yes. 1. Don't use TIMESTAMP, use DATETIME. Why's that? Other than being the same format and such. When I insert a new entry, how do I get it to automatically populate the DATETIME column? Quote Link to comment https://forums.phpfreaks.com/topic/68379-solved-edit-entry-and-overwrite-existing-string/#findComment-344114 Share on other sites More sharing options...
roopurt18 Posted September 8, 2007 Share Posted September 8, 2007 Insert the new entry and set that column to the value of NOW(). Quote Link to comment https://forums.phpfreaks.com/topic/68379-solved-edit-entry-and-overwrite-existing-string/#findComment-344162 Share on other sites More sharing options...
FridayRain Posted September 8, 2007 Author Share Posted September 8, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/68379-solved-edit-entry-and-overwrite-existing-string/#findComment-344290 Share on other sites More sharing options...
roopurt18 Posted September 8, 2007 Share Posted September 8, 2007 Remove the single quotes from around NOW(). Quote Link to comment https://forums.phpfreaks.com/topic/68379-solved-edit-entry-and-overwrite-existing-string/#findComment-344354 Share on other sites More sharing options...
FridayRain Posted September 8, 2007 Author Share Posted September 8, 2007 Ah. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/68379-solved-edit-entry-and-overwrite-existing-string/#findComment-344395 Share on other sites More sharing options...
FridayRain Posted September 17, 2007 Author Share Posted September 17, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/68379-solved-edit-entry-and-overwrite-existing-string/#findComment-349919 Share on other sites More sharing options...
effigy Posted September 17, 2007 Share Posted September 17, 2007 DATE_FORMAT: %k or %l. Quote Link to comment https://forums.phpfreaks.com/topic/68379-solved-edit-entry-and-overwrite-existing-string/#findComment-349922 Share on other sites More sharing options...
FridayRain Posted September 17, 2007 Author Share Posted September 17, 2007 Ah. I had 'h' in there before. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/68379-solved-edit-entry-and-overwrite-existing-string/#findComment-350183 Share on other sites More sharing options...
FridayRain Posted September 18, 2007 Author Share Posted September 18, 2007 Actually, it didn't work. It's displaying some different time. Here's the code I'm using: echo date('h:ia', strtotime($r[date])); (07:56pm) Where DATE is a datetime type. Quote Link to comment https://forums.phpfreaks.com/topic/68379-solved-edit-entry-and-overwrite-existing-string/#findComment-350221 Share on other sites More sharing options...
FridayRain Posted September 18, 2007 Author Share Posted September 18, 2007 'Eh? Should I make a new topic? Quote Link to comment https://forums.phpfreaks.com/topic/68379-solved-edit-entry-and-overwrite-existing-string/#findComment-350326 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.