How do i put the current date into a field in mysql? and how do i show them from most current post at top and oldest at the bottom.
it displays the Date as: "0000-00-00"
Here is the code i am using for POSTING:
here is the code i am using to DISPLAY:PHP Code:<?PHP
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:
$db = mysql_connect('localhost', 'homtek_dclamp', 'moiola') or die(mysql_error());
mysql_select_db('homtek_homtek', $db) or die(mysql_error());
$sContent = mysql_real_escape_string($_POST['content']);
$sPoster = mysql_real_escape_string($_POST['poster']);
$sSubject = mysql_real_escape_string($_POST['subject']);
$query = "INSERT INTO news VALUES ('', '$sContent', '$sPoster', '$sSubject', 'NOW(YYYY-MM-DD)')";
mysql_query($query, $db) or die(mysql_error());
echo "News Post has been added to database.<br><br>";
echo "Subject: ", $_POST['subject'] ,"<br>";
echo "Content: ", $_POST['content'] ,"<br><br>";
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 wrap=hard name="content" columns="5" rows="10"></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>
<br>[<a href="main.php">Main Page</a>]
<? } ?>
PHP Code:<?php
echo '<table width="620" border="1" bordercolor="white">';
//build our query
$db = mysql_connect('localhost', 'homtek_dclamp', 'moiola') or die(mysql_error());
mysql_select_db('homtek_homtek', $db) or die(mysql_error());
$query = "SELECT * FROM `news` LIMIT 5 ORDER BY `news_id`";
$query = mysql_query($query, $db) or die(mysql_error());
//loop through each record
while($array = mysql_fetch_array($query)) {
//print out the field values and values using print_r
echo '<tr>';
echo '<td width="100" border="1" bordercolor="black">';
print_r($array['date']."<br>");
print_r($array['poster']."<br>");
echo '</td>';
echo '<td width="500" border="1" bordercolor="black">';
print_r("<b>".$array['subject']."</b><br><br>");
print_r($array['news']."<br>");
echo '</td>';
echo '</tr>';
}
echo '</table>';
echo '<br>[<a href="news.php">View All News</a>]';
?>




Reply With Quote