foevah Posted May 5, 2007 Share Posted May 5, 2007 Hi I have tried the sql query below but it didnt work: mysql_query("UPDATE `php_blog` SET `timecode` = '".mktime (0,0,0,10,31,2006)."' WHERE `id`='1'"); The browser returned: Can't modify the column 'timestamp' to the table 'php_blog' in the database. Query was empty I am trying to change the timestamp manually. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/50103-how-to-editupdate-timestamp/ Share on other sites More sharing options...
MadTechie Posted May 5, 2007 Share Posted May 5, 2007 use CURRENT_TIMESTAMP or NOW() ie mysql_query("UPDATE `php_blog` SET `timecode` = 'NOW()' WHERE `id`='1'"); Quote Link to comment https://forums.phpfreaks.com/topic/50103-how-to-editupdate-timestamp/#findComment-246019 Share on other sites More sharing options...
londonjustin Posted May 5, 2007 Share Posted May 5, 2007 This doesn't really answer your query, but I've stopped using timestamp recently due to inconsistencies with different versions of mysql. Instead I use a datetime field and something similar to the following: $currenttime = date('Y-m-d H:i:s'); mysql_query("UPDATE `php_blog` SET `timecode` = '$currenttime' WHERE `id`='1'"); You can of course put the date() code as the value of a hidden form field and post it to the database that way... Quote Link to comment https://forums.phpfreaks.com/topic/50103-how-to-editupdate-timestamp/#findComment-246072 Share on other sites More sharing options...
foevah Posted May 5, 2007 Author Share Posted May 5, 2007 MadTechie - I just tried what you suggested and I got the same browser responce: mysql_query("UPDATE `php_blog` SET `timecode` = 'NOW(0,0,0,10,31,2006)' WHERE `id`='1'"); Browser: Can't modify the column 'timestamp' to the table 'php_blog' in the database. Query was empty $currenttime = date('Y-m-d H:i:s'); mysql_query("UPDATE `php_blog` SET `timecode` = '$currenttime' WHERE `id`='1'"); You can of course put the date() code as the value of a hidden form field and post it to the database that way... I am not sure how to apply our suggestions londonjustin.. This is what my blog table looks like when I view data in dreamweaver: I want to change all the 00000000 entries with the dates they were entered into the db.. for some reason they have been deleted. Once I can change these dates I will reset the blog. Quote Link to comment https://forums.phpfreaks.com/topic/50103-how-to-editupdate-timestamp/#findComment-246125 Share on other sites More sharing options...
foevah Posted May 5, 2007 Author Share Posted May 5, 2007 I also got query was empty with CURRENT_TIMESTAMP.. I can edit everything else apart from the timestamp using a form. I am trying to do it manually because when I edit an entry the date is lost changing to 00000000 shown in the picture above.. $currenttime = date('Y-m-d H:i:s'); mysql_query("UPDATE `php_blog` SET `timecode` = '$currenttime' WHERE `id`='1'"); where do i put (0,0,0,10,31,2006) I tried: $currenttime = date(0,0,0,10,31,2006'); mysql_query("UPDATE `php_blog` SET `timecode` = '$currenttime' WHERE `id`='1'"); Browser: Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/hullweb/public_html/jecgardner/blog_test2/entry/update_timestamp.php on line 7 Quote Link to comment https://forums.phpfreaks.com/topic/50103-how-to-editupdate-timestamp/#findComment-246149 Share on other sites More sharing options...
londonjustin Posted May 5, 2007 Share Posted May 5, 2007 I think you're getting things a little mixed up there. For the current date you'd need something like: $currenttime = strtotime('today'); or for your specified date try: $newdate = strtotime('October 31 2006'); mysql_query("UPDATE `php_blog` SET `timecode` = '$newdate' WHERE `id`='1'"); However, to avoid your timestamps getting overwritten every time you change an entry I'd suggest altering your mysql table so that 'timecode' is a datetime type rather than timestamp - you'll have much more control that way. You can set your variables like this: $currenttime = date('Y-m-d H:i:s'); // for the current time when inserting an entry $newdate = date('2006-31-10 00:00:00); // for Oct 31 2006 There might potentially be an error in your naming too. You've specified 'timecode' in your sql query, but the dreamweaver shot you posted suggests the field is called 'timestamp' - unless you've used an alias there and not mentioned it (or I've missed something). Hope this helps. J Quote Link to comment https://forums.phpfreaks.com/topic/50103-how-to-editupdate-timestamp/#findComment-246164 Share on other sites More sharing options...
foevah Posted May 5, 2007 Author Share Posted May 5, 2007 I tried: $newdate = strtotime('October 31 2006'); mysql_query("UPDATE `php_blog` SET `timestamp` = '$newdate' WHERE `id`='1'"); Browser: Can't modify the column 'timestamp' to the table 'php_blog' in the database. Query was empty My posts have an ID and a Record field. The link below is a screenshot of the blog table showing the entires and fields: http://www.webdesignhull.lincoln.ac.uk/jecgardner/blog_test2/images/view_date-01.gif The ID field lists the entries in this order: 1, 2, 88, 89, 7, 33, 32, 62, 85, 90, 92. I want to reset the blog but before I do this I need to know how to change the 0000000 entries to their original date so I can then reset, re-enter entries and then edit dates. I tried: mysql_query("UPDATE php_blog SET timestamp='".time(October 31 2006)."' WHERE id='1"); The browser responded with an error from the query: Parse error: parse error, unexpected T_LNUMBER in /blog/entry/update_timestamp.php on line 6 In this query I am trying to change ID 1 to October 31 2006. ID 1 on the index page is titled "Portfolio PHP blog!" and next to "Leave a comment" should be the date like the entries above. When you rollover "Leave a comment" the URL says "ID=1". When you click on leave a comment the next page says "Posted on Thursday January 01 1970".. I need to change this to October 31 2006 URLfor the index page: http://www.webdesignhull.lincoln.ac.uk/jecgardner/blog_test2/index_vege.php Quote Link to comment https://forums.phpfreaks.com/topic/50103-how-to-editupdate-timestamp/#findComment-246277 Share on other sites More sharing options...
foevah Posted May 5, 2007 Author Share Posted May 5, 2007 I removed - between date and time on the update page: $timestamp = "$year-$month-$date $time"; I can now change the days and years successfully. Only one problem left and that is the months..All the options in the drop down menu on the update page say January. This is the code being used: <select name="month" id="month"> <?php for ($i=1;$i<13;$i++) { $checked = ($i==$row['old_month'])? " selected='selected' " :""; echo "<option $checked; value='$i'>".date('F','2007-'.$i.'-12')."</option>"; } ?> </select> Only ideas why it just lists January? I have also just realized that the entries people have left comments it used to display: For example the entry titled "Missions" if you click "Leave a comment" you can see Igor has left a comment.. This used to say "1 comments" but now it says "Leave a comment" forgetting that someone has left a comment??? http://www.webdesignhull.lincoln.ac.uk/jecgardner/blog_test2/index_vege.php?page=4 Quote Link to comment https://forums.phpfreaks.com/topic/50103-how-to-editupdate-timestamp/#findComment-246307 Share on other sites More sharing options...
londonjustin Posted May 5, 2007 Share Posted May 5, 2007 I've had this problem recently - I solved it by simply putting quotes around the month variable - it's something to do with the select button not reading the month integer correctly, I think it was removing the leading zero and then defaulting to January since it didn't understand any months with single digits (e.g. January to September) - once I put quotes around the month variable it worked for me Quote Link to comment https://forums.phpfreaks.com/topic/50103-how-to-editupdate-timestamp/#findComment-246351 Share on other sites More sharing options...
foevah Posted May 6, 2007 Author Share Posted May 6, 2007 I have this on the blog entry form: Line 92: $timestamp = strtotime($month . " " . $date . " " . $year . " " . $time); Line 195: <select name="month" id="month"> <option value="<?php echo "$current_month"; ?>"><?php echo "$current_month"; ?></option> <option value="January">January</option> <option value="February">February</option> <option value="March">March</option> <option value="April">April</option> <option value="May">May</option> <option value="June">June</option> <option value="July">July</option> <option value="August">August</option> <option value="September">September</option> <option value="October">October</option> <option value="November">November</option> <option value="December">December</option> </select> When I select March from the drop down menu and submit the new blog entry the date doesnt even show.. I then have to edit the entry using the update entry form to apply a date to the entry. This kinda works apart from the month. I can change the day and year successfully for some reason in the drop down menu for the months they all say January ??? This is the code for the drop down menu that shows only January: <?php for ($i=1;$i<13;$i++) { $checked = ($i==$row['old_month'])? " selected='selected' " :""; echo "<option $checked; value='$i'>".date('F','2006-'.$i.'-12')."</option>"; } ?> Update form PHPS: http://www.webdesignhull.lincoln.ac.uk/jecgardner/blog_test2/entry/update.phps Add new blog entrys form PHPS: http://www.webdesignhull.lincoln.ac.uk/jecgardner/blog_test2/entry/uploader.phps Quote Link to comment https://forums.phpfreaks.com/topic/50103-how-to-editupdate-timestamp/#findComment-246380 Share on other sites More sharing options...
londonjustin Posted May 6, 2007 Share Posted May 6, 2007 From the look of your list there you haven't got any code to say when a particular month should be selected. Here's a sample of the code I've gotten to work on my site if it helps: <select name="month" id="month"> <option value="01" <?php if (!(strcmp('01', $month))) {echo "SELECTED";} ?>>January</option> <option value="02" <?php if (!(strcmp('02', $month))) {echo "SELECTED";} ?>>February</option> <option value="03" <?php if (!(strcmp('03', $month))) {echo "SELECTED";} ?>>March</option> <option value="04" <?php if (!(strcmp('04', $month))) {echo "SELECTED";} ?>>April</option> <option value="05" <?php if (!(strcmp('05', $month))) {echo "SELECTED";} ?>>May</option> <option value="06" <?php if (!(strcmp('06', $month))) {echo "SELECTED";} ?>>June</option> <option value="07" <?php if (!(strcmp('07', $month))) {echo "SELECTED";} ?>>July</option> <option value="08" <?php if (!(strcmp('08', $month))) {echo "SELECTED";} ?>>August</option> <option value="09" <?php if (!(strcmp('09', $month))) {echo "SELECTED";} ?>>September</option> <option value="10" <?php if (!(strcmp(10, $month))) {echo "SELECTED";} ?>>October</option> <option value="11" <?php if (!(strcmp(11, $month))) {echo "SELECTED";} ?>>November</option> <option value="12" <?php if (!(strcmp(12, $month))) {echo "SELECTED";} ?>>December</option> </select> I've used individual pulldowns for the day month and year and converted them to dates like this: $year = $_POST['year']; $month = $_POST['month']; $day = $_POST['day']; $adStart = date($year."-".$month."-".$day); $HTTP_POST_VARS['adStart'] = $adStart; (I've used $HTTP_POST_VARS on that last line simply for compatibility with dreamweaver btw). Bear in mind my code above feeds a datetime field in my mysql table rather than a timestamp. I would guess your code should be something like: <option value="December" <?php if (!(strcmp('December', $current_month))) {echo "SELECTED";} ?>>December</option> I could post you an example of my own blog update page if you like? Quote Link to comment https://forums.phpfreaks.com/topic/50103-how-to-editupdate-timestamp/#findComment-246498 Share on other sites More sharing options...
foevah Posted May 6, 2007 Author Share Posted May 6, 2007 Ok I fixed the months problem.. I changed this: <?php for ($i=1;$i<13;$i++) { $checked = ($i==$row['old_month'])? " selected='selected' " :""; echo "<option $checked; value='$i'>".date('F','2006-'.$i.'-12')."</option>"; } ?> too: <?php for ($i=1;$i<13;$i++) { $checked = ($i==$row['old_month'])? " selected='selected' " :""; echo "<option $checked; value='$i'>".date('F',mktime(0,0,0,$i,12,2006))."</option>"; } ?> Months work perfectly now I am still trying to figure out how to fix the comments problem.. Quote Link to comment https://forums.phpfreaks.com/topic/50103-how-to-editupdate-timestamp/#findComment-246499 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.