shebbycs Posted April 6, 2013 Share Posted April 6, 2013 taskreportform.php <?php session_start(); if (empty($_SESSION['is_logged_in'])) { header("Location:login.php"); die(); // just to make sure no scripts execute } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Counter Cash OK Form</title> </head> <body bgcolor="#F5D16A"> <form name="form" method="post" action="taskreport.php"> <center><img src="OK.gif" /><br /><h2>OPERATION FORM REPORT<br /><table><tr><td>LOCATION</td><td>:</td> <td><?PHP echo $_SESSION['branchcodename']; ?></td></tr></table></h2></center> <table border=0 align=center> <tr align="center"> <td><b>DATE</b></td> <td>:</td> <td><input type=text name="tdate" value="<?php date_default_timezone_set('Asia/Kuala_Lumpur');echo $date = date('d-m-Y');?>" readonly></td> </tr> <tr align="center"> <td><b>TIME</b></td> <td>:</td> <td><input type=text name="ttme"></td> </tr> <tr align="center"> <td><b>NAME</b></td> <td>:</td> <td><input type=text name="tname"></td> </tr> <tr align="center"> <td><b>TASKS</b></td> <td>:</td> <td><textarea name="ttask" rows="2" cols="16"></textarea></td> </tr> <tr align="center"> <td><b>OPERATIONS</b></td> <td>:</td> <td><textarea name="toperation" rows="7" cols="16"></textarea></td> </tr> <tr align="center"> <td><b>ACTION & RESULTS</b></td> <td>:</td> <td><textarea name="taction" rows="2" cols="16"></textarea></td> </tr> <input type="hidden" name="thisID"> <tr> <td colspan="3" align="center"><input type=submit name="submit" value="Submit"></td> </tr> </table> </form> </body> </html> taskreport.php $pid = mysql_real_escape_string($_POST['thisID']) $date; // not yet convert $time; // not yet convert $sql = mysql_query("INSERT INTO task_report (ID,DATE) VALUES ('ID','$DATE.$TIME')") It is like this ? Quote Link to comment https://forums.phpfreaks.com/topic/276605-how-to-combine-date-and-time-in-one-mysql-query/ Share on other sites More sharing options...
trq Posted April 6, 2013 Share Posted April 6, 2013 Your question si not at all clear. Quote Link to comment https://forums.phpfreaks.com/topic/276605-how-to-combine-date-and-time-in-one-mysql-query/#findComment-1423256 Share on other sites More sharing options...
shebbycs Posted April 9, 2013 Author Share Posted April 9, 2013 Your question si not at all clear. ok I explain one by one My date format is datetime in mysql In PHP, i separated date and time where date is default date but time is the user selection for example I divide by dropdownlist for example 2.45 pm i got 4 dropdownlist which is 2 , 4,5 and pm so simply I got one txt name= date and 4 dropdownlist name and total is 5 name My main question was $sql = mysql_query("INSERT INTO task_report (ID,DATE) VALUES ('ID','$DATE.$TIME')") how to insert 5 names in one value for date I hope you understand Quote Link to comment https://forums.phpfreaks.com/topic/276605-how-to-combine-date-and-time-in-one-mysql-query/#findComment-1423623 Share on other sites More sharing options...
Psycho Posted April 9, 2013 Share Posted April 9, 2013 hope you understand Barely. You can try and concatenate a bunch of different variables inside the query for a single field value. But, that's a poor process in my opinion. I would suggest you concatenate the variables outside the query as the complete value and then use that inside the query. And, anyways, what you have will not work. You use the period to concatenate string in PHP. But, you have two variables inside a quoted string - so the period would be interpreted as a literal character of the period. $sql = mysql_query("INSERT INTO task_report (ID,DATE) VALUES ('ID','$DATE.$TIME')") If $DATE = '2013-04-08' and $TIME = '2:45 pm' the quwery would end up as INSERT INTO task_report (ID,DATE) VALUES ('ID','2013-04-08.2:45 pm') 1) You need a space between the date and time 2) The period is out of place 3) '2:45 pm' is not a valid time. You will need to convert any PM time to be +12 hours Example code $date = date('Y-m-d'); $hour = ($_POST['period']=='pm') ? intval($_POST['hour']+12) : intval($_POST['hour']); $minutes = intval($_POST['minutes']); $datetime = sprintf("%s %2d:%2d:00", $date, $hour, $minutes); $query = "INSERT INTO task_report (ID,DATE) VALUES ('ID','$datetime')"; $sql = mysql_query($query); Quote Link to comment https://forums.phpfreaks.com/topic/276605-how-to-combine-date-and-time-in-one-mysql-query/#findComment-1423626 Share on other sites More sharing options...
Jessica Posted April 9, 2013 Share Posted April 9, 2013 (edited) Edit: damn ip board Edited April 9, 2013 by Jessica Quote Link to comment https://forums.phpfreaks.com/topic/276605-how-to-combine-date-and-time-in-one-mysql-query/#findComment-1423627 Share on other sites More sharing options...
shebbycs Posted April 9, 2013 Author Share Posted April 9, 2013 Barely. You can try and concatenate a bunch of different variables inside the query for a single field value. But, that's a poor process in my opinion. I would suggest you concatenate the variables outside the query as the complete value and then use that inside the query. And, anyways, what you have will not work. You use the period to concatenate string in PHP. But, you have two variables inside a quoted string - so the period would be interpreted as a literal character of the period. $sql = mysql_query("INSERT INTO task_report (ID,DATE) VALUES ('ID','$DATE.$TIME')") If $DATE = '2013-04-08' and $TIME = '2:45 pm' the quwery would end up as INSERT INTO task_report (ID,DATE) VALUES ('ID','2013-04-08.2:45 pm') 1) You need a space between the date and time 2) The period is out of place 3) '2:45 pm' is not a valid time. You will need to convert any PM time to be +12 hours Example code $date = date('Y-m-d'); $hour = ($_POST['period']=='pm') ? intval($_POST['hour']+12) : intval($_POST['hour']); $minutes = intval($_POST['minutes']); $datetime = sprintf("%s %2d:%2d:00", $date, $hour, $minutes); $query = "INSERT INTO task_report (ID,DATE) VALUES ('ID','$datetime')"; $sql = mysql_query($query); Thanks a lot guru I will let u know if I succeed doing that date and time anyhow again thanks a lot and also jessica who also previously helping me a lot Quote Link to comment https://forums.phpfreaks.com/topic/276605-how-to-combine-date-and-time-in-one-mysql-query/#findComment-1423636 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.