JamesCliff
Programmer
Hi guys.
I have a mysql table called shout. Its designed in the following way:
I use the following php script to populate the table:
However when i run the above script all is entered into the table as it should be except for the date. I get the default 0000-00-00 00:00:00 in every single field entry, when i should be getting the actual date and time. Ive used the NOW() function within the insert code as im supposed to, but for some reason it just wont insert the date and time into the table.
Also when i manage to get it working, how would i display the date and time on a php script as in the following way: Sep 23rd, 2002 at 01:09:30 hrs.
How would i go about formatting it in that way and implementing it into a php script to display like that instead of just showing the 0000-00-00 00:00:00 (when it works) format which is called from the database?
Help on both of these issues is greatly appriciated.
Thanks alot
Jim
I have a mysql table called shout. Its designed in the following way:
Code:
CREATE TABLE `shout` (
`id` int(5) NOT NULL auto_increment,
`date` datetime NOT NULL default '0000-00-00 00:00:00',
`message` text NOT NULL,
`name` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`),
FULLTEXT KEY `message` (`message`)
) TYPE=MyISAM;
I use the following php script to populate the table:
Code:
<?php
if(isset($_POST['add']))
{
$host = 'HOST';
$user = 'USER';
$pass = 'PASS';
$db = 'DB';
$connection = mysql_connect($host, $user, $pass) or die ("Unable to
connect!");
mysql_select_db($db) or die ("Unable to select database!");
$message = $_POST['message'];
$name = $_POST['name'];
$query = "INSERT INTO shout(id, date, message, name) VALUES('','NOW()','$message','$name')";
mysql_query($query) or die('Error, insert query failed');
header('Location: index.php?page=admin/shout/shout');
}
else
{
?>
<form method="post">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<tr>
<td>Message:</td>
</tr>
<tr>
<td><input name="message" type="text" id="message"></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>Name:</td>
</tr>
<tr>
<td><input name="name" type="text" id="name"></td>
</tr>
<tr>
<td width="100"> </td>
</tr>
<tr>
<td><input name="add" type="submit" id="add" value="Post Message"></td>
</tr>
</table>
</form>
<?php
}
?>
However when i run the above script all is entered into the table as it should be except for the date. I get the default 0000-00-00 00:00:00 in every single field entry, when i should be getting the actual date and time. Ive used the NOW() function within the insert code as im supposed to, but for some reason it just wont insert the date and time into the table.
Also when i manage to get it working, how would i display the date and time on a php script as in the following way: Sep 23rd, 2002 at 01:09:30 hrs.
How would i go about formatting it in that way and implementing it into a php script to display like that instead of just showing the 0000-00-00 00:00:00 (when it works) format which is called from the database?
Help on both of these issues is greatly appriciated.
Thanks alot
Jim