Mr Chris Posted May 12, 2007 Share Posted May 12, 2007 Hi, When i'm grabbing a row from my database and then trying to UPDATE those details it's not updating and I don't see why: DB Structure story_id (int 1) published_web_date_time (timestamp / datetime 0000-00-00 00:00:00) Now in the structure above i've tried both published_web_date_time as both a timestamp and datetime field as I was told you can't update a timestamp field in MYSQL using PHP, which I thought was wierd? But nomatter what I change published_web_date_time to field wise it still does not update. If you look at my form below when I GET the data I get the published_web_date_time split into two textfields as shown in the form below, but when it comes to updating these textfields with new values it does not save the data to the database upon sumbit? Any ideas? Thanks <?php // ** Get the requested story id from the database ** if(isset($_GET['story_id'])) { $result = mysql_query("Select * From cms_test where story_id=".$_GET['story_id']); $row = mysql_fetch_array($result); $date_time_array = explode(" ",$row['published_web_date_time']); $published_web_date = $date_time_array[0]; $published_web_time = $date_time_array[1]; } // ** If Submit is hit do your stuff ** if (isset($_POST['Submit'])) { $published_web_date_time = $_POST['published_web_date_time']; // ** Check for Required Fields with IF statements ** if (empty($published_web_date)){ $error = "** no time! **"; } else if (empty($published_web_time)){ $error = "** no date! **"; // ** If all of the statements are true then ** } else { $query = mysql_query("Update cms_test set published_web_date_time='$published_web_date $published_web_time' where story_id=".$_GET['story_id']); header('Location: done.php'); // ** And finally run the query to add data to the database ** $link = mysql_connect; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); mysql_close(); } } ?> <FORM ACTION="".php" method="post" NAME="frmAdd"> Date: <INPUT NAME="published_web_date" TYPE="text" ID="published_web_date" VALUE="<?php echo $published_web_date?>" SIZE="18"> <br /> <br / > Time: <INPUT NAME="published_web_time" TYPE="text" ID="published_web_time" VALUE="<?php echo $published_web_time?>" SIZE="18"><br /> <br /> <INPUT TYPE="Submit" NAME="Submit" VALUE="Submit" CLASS="button"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/51051-update-timestamp-or-datetime/ Share on other sites More sharing options...
only one Posted May 12, 2007 Share Posted May 12, 2007 my advice would be not to use timestamp and just simply use the date function http://nl3.php.net/manual/en/function.date.php Quote Link to comment https://forums.phpfreaks.com/topic/51051-update-timestamp-or-datetime/#findComment-251235 Share on other sites More sharing options...
Mr Chris Posted May 12, 2007 Author Share Posted May 12, 2007 Thanks, but that's not an option as I want to specify a specific DATE and TIME that a piece of news appears on my website. Any other suggestions please? Chris Quote Link to comment https://forums.phpfreaks.com/topic/51051-update-timestamp-or-datetime/#findComment-251260 Share on other sites More sharing options...
otuatail Posted May 12, 2007 Share Posted May 12, 2007 Thats not a problem if you know the date and time you want then you can get it's time stamp. Time stamps are great. you can format them in any way you want $unixStamp = strtotime("03-05-2007"); $datetime = date('D d-M-Y',$unixStamp); Des. Quote Link to comment https://forums.phpfreaks.com/topic/51051-update-timestamp-or-datetime/#findComment-251264 Share on other sites More sharing options...
Mr Chris Posted May 12, 2007 Author Share Posted May 12, 2007 Thanks Des, but I don't understand what you mean by that. If I have 120 records in my database and I am pulling out one record random i'm not going to know the date and time (timestamp or datetime) for each record. So is there no way of using UPDATE in the code i've posted then? Chris Quote Link to comment https://forums.phpfreaks.com/topic/51051-update-timestamp-or-datetime/#findComment-251394 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.