Jump to content

time will not update


chiprivers

Recommended Posts

I have the following script to create a form on a project I am working on:

[code]

<?
require 'connect.php';

if (isset($_POST['incident_number'])) {
$hour = substr($_POST['incident_time'],0,2);
$min = substr($_POST['incident_time'],2,2);
$init = mktime($hour,$min,0,$_POST['date_month'],$_POST['date_day'],$_POST['date_year']);
$qry = "INSERT INTO incidents (reference,title,init,status) VALUES (".$_POST['incident_number'].",\"".$_POST['incident_desc']."\",".$init.",1)";
$create = mysql_query($qry);
}
?>
<link href="style/new_incident.css" rel="stylesheet" type="text/css">

<div id="new_incident">
<h1>New Incident</h1>
<h2>Enter details below and click '<span class="link">Continue</span>' to create a new relief plan</h2>
<form id="new_incident_form" name="new_incident_form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td><label for="incident_number">Incident Number:</label></td>
<td><input id="incident_number" name="incident_number" type="text"></td>
</tr>
<tr>
<td>
<label for="start_date">Date and Time of Call:</label>
</td>
<td>
<select id="date_day" name="date_day">
<?php
for ($d=1; $d<=31; $d++) {
echo "<option ";
if ($d == date("d")) {
echo "selected ";
}
echo "value=\"$d\">$d</option>\n";
}
?>
</select>
<select id="date_month" name="date_month">
<?php
for ($m=1; $m<=12; $m++) {
echo "<option ";
if ($m == date("m")) {
echo "selected ";
}
$M = date("M",mktime(0,0,0,$m));
echo "value=\"$m\">$M</option>\n";
}
?>
</select>
<select id="date_year" name="date_year">
<?php
for ($y=date("Y"); $y>=(date("Y")-1); $y--) {
echo "<option ";
if ($y == date("Y")) {
echo "selected ";
}
echo "value=\"$y\">$y</option>\n";
}
?>
</select>
</td>
<td>
<input id="incident_time" name="incident_time" type="text" value="<?php echo date("Hm", time()); ?>">
</td>
</tr>
<tr>
<td>
<label for="incident_desc">Incident Description:</label>
</td>
<td colspan="2">
<input id="incident_desc" name="incident_desc" type="text">
</td>
</tr>
<tr>
<td colspan="3"><span class="submit_link" onClick="document.new_incident_form.submit()">Continue</span></td>
</tr>
</table>
</form>

</div>

[/code]

The problem is the time is not updating! It just keeps showing the same time? Is this a problem with my script is there a problem with my server/bowser?
Link to comment
https://forums.phpfreaks.com/topic/33749-time-will-not-update/
Share on other sites

from what i can see, you're actually telling it to show the CURRENT date, when you're using:

if ($d = date("d))
if ($d = date("m"))
etc

my guess is that you need to use [url=http://www.php.net/date]date[/url]'s second parameter (a timestamp). not setting the second parameter will make 'date' default to the current time.

what time SHOULD it show?
Link to comment
https://forums.phpfreaks.com/topic/33749-time-will-not-update/#findComment-158258
Share on other sites

It is supposed to show the current time, ie the current time will default into the input box at the time the page loads. 

But for some reason, the time that is defaulting into the box is remaining at the time that it was when I first loaded up the script, when ever I refresh the page it should change to the current time, but it is not!
Link to comment
https://forums.phpfreaks.com/topic/33749-time-will-not-update/#findComment-158391
Share on other sites

Guest rancid-tea
It is showing the date in the date boxes, and then it is showing the month and day instead of the time. You need to change 'd' and 'm' to reflect the hour and minutes in the format you want.

Check out [url=http://us3.php.net/date]http://us3.php.net/date[/url] for the format you want.
Link to comment
https://forums.phpfreaks.com/topic/33749-time-will-not-update/#findComment-158418
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.