writing the date - for input into database
Posted: Sun Oct 08, 2006 4:23 pm
I am creating a simple news script for my site. i need to know how to show the date.
thanks
thanks
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
<?PHP
if (!$logged_in_admin) {
echo "<h1>Please login</h1>";
echo "You must be loged in to see this page!";
echo "<A HREF='login.php'>Please click here to login.</A>";
exit;
}
if(isset($_POST['subject'], $_POST['content'], $_POST['poster'])){
//form was submitted, do some error checking on the variables submitted and add in your query here
//for example:
mysql_connect('localhost', 'homtek_dclamp', 'my_password');
mysql_select_db('homtek_homtek');
mysql_query("INSERT INTO table VALUES('" . $_POST['content'] . "', '" . $_POST['poster'] . "', '" . $_POST['subject'] . "')");
echo "News has been added to database.";
echo "<a href='main.php'>Main Page</a>";
}else{
?>
<form action="add_news.php" method="POST">
Subject:<br>
<input type=text maxlength="25" name="subject"><br><br>
News Content:<br>
<textarea name="content"></textarea><br>
<input type="hidden" name="poster" value="<?PHP echo $logged_in_admin; ?>">
<input type="hidden" name="date" value="DATE_HERE">
<input type="submit" value="Submit"> <input type="reset" value="Reset Form">
</form>
<? } ?>*cough* you rely directly on an input/hidden to identify the user/admin? You might want to look up some login/session tutorialsif (!$logged_in_admin) {
[...]
<input type="hidden" name="poster" value="<?PHP echo $logged_in_admin; ?>">
Code: Select all
INSERT INTO
table
('content', 'poster', 'subject', 'date')
VALUES
('some content', 'a poster', 'the subject', '2006-10-09')DATE_FORMAT(date,format)
Formats the date value according to the format string.
The following specifiers may be used in the format string.
...
that is from a tourtorialvolka wrote:You might want to look up some login/session tutorials![]()
Code: Select all
<input name="date" type=hidden value="<?PHP echo DATE_FORMAT(date,yyyy-mm-yy); ?>">Code: Select all
INSERT INTO
tablename
(`datefield`)
VALUES
(Now())Code: Select all
$sql = "SELECT date_field FROM news WHERE 1";
$query_result = mysql_query($sql);
while ($show = mysql_fetch_array($query_result)) {
echo date("M, d Y", $show['date_field']); //this will show you "Oct, 07 2006"
}