Jump to content

Date saving problem


rajaahsan

Recommended Posts

hy every one i have two files one is index.php and second insert.php as follow,

 

index.php 



<html>
<body>

<form action="insert.php" method="post">
Time <input type="text" name="time" />
<input type="submit" />
</form>

<?php
$ctime = date('h:i:s A');
echo "Current time is : " . $ctime ;
echo "<br>";

$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("time", $con);

$result = mysql_query("SELECT * FROM time");

while($row = mysql_fetch_array($result))
  {
  echo date('h:i:s A', strtotime($row['time']));
  
  echo "<br />";
  }

mysql_close($con);
?> 


</body>
</html> 

 

here is my insert.php file code,

 


<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("time", $con);

$sql="INSERT INTO time (time )
VALUES
('$_POST[time]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";
echo "<br>";
echo "<a href='index.php'>Home</a>";

mysql_close($con)
?>

 

 

this code work fine but the form which submit the value of time in database whos code is in index.php file above,

i have to enter time in the form text field like this 17:00 and it save the value in database but,

i want to enter time in the form text field like this 05:00 PM which automatically save the value in database as 17:00

what should i do with the code help me please

thanks

Link to comment
https://forums.phpfreaks.com/topic/237445-date-saving-problem/
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.