Mr Chris Posted May 9, 2007 Share Posted May 9, 2007 Hi Guys, I was wondering if someone can help me with an update problem. Basically in my content management system I want to be able to call a date and time from a database record and show those values in two textboxes for the user to update them: However. In my cms the date and time is saved in one field named: web_date_time (timestamp) ie: 2007-04-26 09:43:48 So what I want to do, is when I GET a record it splits up the web_date_time and places them in two different textboxes as shown below. Can anyone help. Thanks Chris <?php // ** Get the requested story id from the database ** if(isset($_GET['story_id'])) { $result = mysql_query("Select * From cms_stories2 where story_id=".$_GET['story_id']); $row = mysql_fetch_array($result); $web_date_time = $row['web_date_time']; } // ** POST DATA ** if (isset($_POST['Submit'])) { $web_date = $_POST['web_date']; $web_time = $_POST['web_time']; // ** Check for Required Fields with IF statements ** if (empty($web_date)){ $error = "** No Pub web date! **"; } else if (empty($web_time)){ $error = "** No web time **"; // ** If all of the statements are true then ** } else { $query = mysql_query("UPDATE cms_test set web_date_time='$web_date"." "."$web_time' where story_id=".$_GET['story_id']); header('Location: edit_list.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(); } } ?> <html> <head> <title>Time & Date</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <FORM ACTION="".php" method="post" NAME="frmAdd"> <p> Date: <INPUT NAME="web_date" TYPE="text" ID="web_date" VALUE="<?php echo $web_date?>" SIZE="48"> </p> <p> Time: <INPUT NAME="web_date" TYPE="text" ID="web_time" VALUE="<?php echo $web_time?>" SIZE="48"> <p> <input type="Submit" name="Submit" value="Submit"> </p> </form> Link to comment https://forums.phpfreaks.com/topic/50639-solved-get-problem/ Share on other sites More sharing options...
only one Posted May 9, 2007 Share Posted May 9, 2007 check the date manuall http://nl3.php.net/date date = date(Y-m-d); tame = date(H:i:s); Link to comment https://forums.phpfreaks.com/topic/50639-solved-get-problem/#findComment-248914 Share on other sites More sharing options...
jitesh Posted May 9, 2007 Share Posted May 9, 2007 check name of time textbox <INPUT NAME="web_date" TYPE="text" ID="web_date" VALUE="<?php echo $web_date?>" SIZE="48"> </p> <p> Time: <INPUT NAME="web_date[ This should be web_time]" TYPE="text" ID="web_time" VALUE="<?php echo $web_time?>" SIZE="48"> Link to comment https://forums.phpfreaks.com/topic/50639-solved-get-problem/#findComment-248942 Share on other sites More sharing options...
Mr Chris Posted May 10, 2007 Author Share Posted May 10, 2007 Thanks, but still a bit confused So do you mean something like this: <?php // ** Get the requested story id from the database ** if(isset($_GET['story_id'])) { $result = mysql_query("Select * From cms_stories2 where story_id=".$_GET['story_id']); $row = mysql_fetch_array($result); $web_date_time = $row['web_date_time']; } // ** POST DATA ** if (isset($_POST['Submit'])) { $web_date = $_POST['web_date']; $web_time = $_POST['web_time']; // ** Check for Required Fields with IF statements ** if (empty($web_date)){ $error = "** No Pub web date! **"; } else if (empty($web_time)){ $error = "** No web time **"; // ** If all of the statements are true then ** } else { $query = mysql_query("UPDATE cms_test set web_date_time='$web_date"." "."$web_time' where story_id=".$_GET['story_id']); header('Location: edit_list.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(); } } ?> <html> <head> <title>Time & Date</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <FORM ACTION="".php" method="post" NAME="frmAdd"> <p> Date: <INPUT NAME="web_date" TYPE="text" ID="web_date" VALUE="<?php echo $web_date_time = date(Y-m-d); ?>" SIZE="18"> </p> <p> Time: <INPUT NAME="web_time" TYPE="text" ID="web_time" VALUE="<?php echo $web_date_time = date(H:i:s); ?>" SIZE="18"> <p> <input type="Submit" name="Submit" value="Submit"> </p> </form> So when I get a record from the database the record gets the web_date_time and then splits this timestamp value into both the web_date and web_time textboxes? Or am I undertsanding it wrong? Link to comment https://forums.phpfreaks.com/topic/50639-solved-get-problem/#findComment-249718 Share on other sites More sharing options...
jitesh Posted May 10, 2007 Share Posted May 10, 2007 if(isset($_GET['story_id'])) { $result = mysql_query("Select * From cms_stories2 where story_id=".$_GET['story_id']); $row = mysql_fetch_array($result); // Assume $row['web_date_time'] has such kind of type 2007-05-10 12:12:10 $date_time_array = explode(" ",$row['web_date_time']); $web_date = $date_time_array[0]; $web_time = $date_time_array[1]; echo $web_date ; echo $web_time ; } p> Date: <INPUT NAME="web_date" TYPE="text" ID="web_date" VALUE="<?php echo $web_date ;?>" SIZE="18"> </p> <p> Time: <INPUT NAME="web_time" TYPE="text" ID="web_time" VALUE="<?php echo $web_date ;?>" SIZE="18"> <p> Link to comment https://forums.phpfreaks.com/topic/50639-solved-get-problem/#findComment-249727 Share on other sites More sharing options...
nikkieijpen Posted May 10, 2007 Share Posted May 10, 2007 Date: <INPUT NAME="web_date" TYPE="text" ID="web_date" VALUE="<?php echo date("Y-m-d", strtotime($web_time)); ?>" SIZE="48"> Time: <INPUT NAME="web_date" TYPE="text" ID="web_time" VALUE="<?php echo date("H:i:s", strtotime($web_time)); ?>" SIZE="48"> Link to comment https://forums.phpfreaks.com/topic/50639-solved-get-problem/#findComment-249757 Share on other sites More sharing options...
Mr Chris Posted May 10, 2007 Author Share Posted May 10, 2007 Many Thanks Guys! Link to comment https://forums.phpfreaks.com/topic/50639-solved-get-problem/#findComment-249777 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.