Mr Chris Posted May 8, 2007 Share Posted May 8, 2007 Hi All, I'm posting data into a MYSQL database, which works fine using the schema below and the php form below: cms_test story_id (int 3) web_date (date) web_time (time) <?php // ** 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 = "INSERT INTO cms_test(published_web_date,published_web_time) VALUES ('$web_date','$web_time')"; $query = mysql_query($query); $story_id=mysql_insert_id(); header("Location: done.php?story_id=$story_id"); // ** 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 type="text" size="48" maxlength="255" name="web_date" <?php if(isset($web_date)) echo "value='$web_date'"; ?>/> </p> <p> Time: <input type="text" size="48" maxlength="255" name="web_time" <?php if(isset($web_time)) echo "value='$web_time'"; ?>/> <p> <input type="Submit" name="Submit" value="Submit"> </p> </form> However, i've now normalized my database in the following format: cms_test story_id (int 3) web_date_time (timestamp) So my question is how can I modify the form above to post two values ie web_date and web_time, but this time these values are JUST saved in one field - web_date_time in the format: 0000-00-00 00:00:00 Thanks Chris Link to comment https://forums.phpfreaks.com/topic/50455-solved-post-two-values-into-one-mysql-field/ Share on other sites More sharing options...
Thierry Posted May 8, 2007 Share Posted May 8, 2007 Wouldn't it simply work to put the two variables behind one another? $web_date_time = "$web_date$web_time"; Link to comment https://forums.phpfreaks.com/topic/50455-solved-post-two-values-into-one-mysql-field/#findComment-247928 Share on other sites More sharing options...
jitesh Posted May 8, 2007 Share Posted May 8, 2007 $web_date_time = $web_date." ".$web_time"; Link to comment https://forums.phpfreaks.com/topic/50455-solved-post-two-values-into-one-mysql-field/#findComment-247930 Share on other sites More sharing options...
Mr Chris Posted May 8, 2007 Author Share Posted May 8, 2007 Thanks Guys, But I don't quite understand. Do you mean something like: <?php // ** 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 = "INSERT INTO cms_test(web_date_time) VALUES ('$web_date$web_time')"; $query = mysql_query($query); $story_id=mysql_insert_id(); header("Location: done.php?story_id=$story_id"); // ** 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 type="text" size="48" maxlength="255" name="web_date" <?php if(isset($web_date)) echo "value='$web_date'"; ?>/> </p> <p> Time: <input type="text" size="48" maxlength="255" name="web_time" <?php if(isset($web_time)) echo "value='$web_time'"; ?>/> <p> <input type="Submit" name="Submit" value="Submit"> </p> </form> IE the change is where my INSERT query is. That does insert a new record into the database, but enters everything as 0000-00-00 00:00:00? Thanks Chris Link to comment https://forums.phpfreaks.com/topic/50455-solved-post-two-values-into-one-mysql-field/#findComment-247939 Share on other sites More sharing options...
jitesh Posted May 8, 2007 Share Posted May 8, 2007 $query = "INSERT INTO cms_test(web_date_time) VALUES ('$published_web_date"." "."$published_web_time')"; Link to comment https://forums.phpfreaks.com/topic/50455-solved-post-two-values-into-one-mysql-field/#findComment-247940 Share on other sites More sharing options...
Mr Chris Posted May 8, 2007 Author Share Posted May 8, 2007 I see! Thanks Link to comment https://forums.phpfreaks.com/topic/50455-solved-post-two-values-into-one-mysql-field/#findComment-247944 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.