Dyvn Posted May 29, 2008 Share Posted May 29, 2008 Hi there, I recently asked about sorting entries into an SQL database, and this is what I've come up with... News submission page (news.php) <form method="post" action="submit.php"> <table align="center" cellpadding="6" cellspacing="0"> <tr> <td>Name :</td> <td><input type="text" name="name"></td> </tr> <tr> <td>Subject :</td> <td><input type="text" name="subject"></td> </tr> <tr> <td valign="top">Message :</td> <td><textarea name="message" cols="30" rows="6"></textarea></td> </tr> <tr> <td valign="top">Pass :</td> <td><input type="password" name="password"</td> </tr> <tr> <td> </td> <td><input type="submit" name="submit" value="Add" style="cursor:pointer"> <input type="reset" name="reset" value="Clear" style="cursor:pointer"></td> </tr> </table> The submission (submit.php) <?php if ($_POST[password] == "password") { $con = mysql_connect("eidt","jtdatabase","edit"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("jtdatabase", $con); $sql="INSERT INTO news (name, message, subject) VALUES ('$_POST[name]','$_POST[message]','$_POST[subject]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "Your news had been added."; mysql_close($con); } else { echo "Incorrect password."; } ?> The display: <? $con = mysql_connect("edit","jtdatabase","edit") or die(mysql_error()); mysql_select_db(jtdatabase) or die(mysql_error()); $query = "SELECT `name`, `subject`, `message`, `date` FROM `news` order by `date` DESC LIMIT 5"; $result = mysql_query($query); echo "<center>"; while($r = mysql_fetch_array($result)) { echo "<div class='title'><u>" . $r['subject'] . "</u></div>"; echo $r['message']; echo "<br>Added by: " . $r['name'] . " | Date: " . $r['date']; echo "<hr color='#EAEAEA' width='80%'>"; } echo "</center>"; mysql_close($con); ?> I have a column "date" as a timestamp for each entry. But every time I make an entry, the time stamp is still "0000-00-00 00:00:00", how do I make it change to the time and date from when the person hit the "submit" button? Any help is appreciated, thanks! Link to comment https://forums.phpfreaks.com/topic/107869-small-news-page-cont/ Share on other sites More sharing options...
aeafisme23 Posted May 29, 2008 Share Posted May 29, 2008 I do not see you passing it through a input box hidden or not. Also if you are pulling the DATE from a database which is giving you the 00:00:00 that is more than likely meaning that there has been nothing put into that input box or through your phpmyadmin/mysql cpanel. Try inserting a date into the MYSQL to a record that has already been inserted. If it now shows a date in the correct format you are not passing the date information from your first form page. Remember php date and a field in mysql called date are two different things be careful.... Link to comment https://forums.phpfreaks.com/topic/107869-small-news-page-cont/#findComment-552953 Share on other sites More sharing options...
DarkWater Posted May 29, 2008 Share Posted May 29, 2008 When you insert the record, fill the timestamp column with NOW(), which is a MySQL function. Link to comment https://forums.phpfreaks.com/topic/107869-small-news-page-cont/#findComment-552970 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.