Jump to content

Recommended Posts

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 ?

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 :)

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);

 

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.