vapour_ Posted June 6, 2008 Share Posted June 6, 2008 Hey, Ok, I have been trying to create a news posting app for my website which involves retrieving 4 values from a table and sticking it into a div tag to be displayed on the main page. I am quite new to PHP and MySQL stuff so my script is messy and probably not even close to correct. Some help/advise would be really helpful. Heres the code at the top of the page: <?php include("db_connect.php"); $query = "SELECT * FROM newsPosts ORDER BY timestamp;"; $result = mysql_query($query) or die ( mysql_error() ); ?> Heres the code for displaying the news: <div class="post"> <h1><?php echo $result["title"]; ?></h1> <div class="post_body"> <p><?php echo $result["message"]; ?></p> </div> <div class="post_info"> <div class="author"><?php echo $result["author"]; ?></div> <div class="timestamp"><?php echo $result["timestamp"]; ?></div> </div></div> The code i used to get the information into the db table is on another page and consists of: <?php include("db_connect.php"); $title = $_POST['title']; $message = $_POST['message']; $author = $_POST['author']; $query = "INSERT INTO newsPosts VALUES ('".$title."', '".$message."', '".$author."', CURRENT_TIMESTAMP)"; $result = mysql_query($query) or die ( mysql_error() ); ?> The variables $title, $message and $author are posted in from a form on another page. If i have made a stupid mistake please forgive me. Thanks in advance for the help. Link to comment https://forums.phpfreaks.com/topic/108944-solved-php-news-posting-application/ Share on other sites More sharing options...
tapos Posted June 6, 2008 Share Posted June 6, 2008 yes you have made a stupid mistake. you didn't fetch the result set from the resource object here is the correction: Heres the code at the top of the page: <?php include("db_connect.php"); $query = "SELECT * FROM newsPosts ORDER BY timestamp;"; $result = mysql_query($query) or die ( mysql_error() ); //fetching result set while ($row = mysql_fetch_assoc($result)){ //Heres the code for displaying the news: ?> <div class="post"> <h1><?php echo $row["title"]; ?></h1> <div class="post_body"> <p><?php echo $row["message"]; ?></p> </div> <div class="post_info"> <div class="author"><?php echo $row["author"]; ?></div> <div class="timestamp"><?php echo $row["timestamp"]; ?></div> </div></div> <? } ?> for more information http://www.php.net/manual/en/function.mysql-query.php Link to comment https://forums.phpfreaks.com/topic/108944-solved-php-news-posting-application/#findComment-558932 Share on other sites More sharing options...
vapour_ Posted June 6, 2008 Author Share Posted June 6, 2008 Dang. Sorry about that. Thanks for correcting it. Link to comment https://forums.phpfreaks.com/topic/108944-solved-php-news-posting-application/#findComment-558939 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.