-3
 <div id="main_content"> 
<?php
 //error_reporting(0);
  include("includes/connect.php");

 $select_posts = " select * from posts ";

 $run = mysql_query($select_posts);

while($row = mysql_fetch_array($run_posts)) {

$post_id = $row['post_id'];
$post_title = $row['post_title'];
$post_date = $row['post_date'];
$post_author = $row['post_author'];
$post_image = $row['post_image'];
$post_keywords = $row['post_keywords'];
$post_content = $row['post_content'];



?>

<h2> <?php echo $post_title; ?> </h2>

<?php } ?>
</div>

While creating CMS I am displaying the content on main page but getting usual error and warning

Notice: Undefined variable: run_posts in C:\wamp\www\CMS\includes\main_content.php on line 10

Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\wamp\www\CMS\includes\main_content.php on line 10

Community
  • 1
  • 1

3 Answers3

1
$run = mysql_query($select_posts);

while($row = mysql_fetch_array($run_posts)) {

you are trying to fetch $run_posts instead of $run variable

Change the loop to while($row = mysql_fetch_array($run)) {

Baby Groot
  • 4,637
  • 39
  • 52
  • 71
Athipatla
  • 422
  • 2
  • 10
0

You're trying to fetch results from $run_posts, but your MySQL query is actually the $run variable. Look at the error message, that's exactly what it says.

Also, please do not use mysql_* anymore, switch to mysqli_ or PDO.

lxg
  • 12,375
  • 12
  • 51
  • 73
0

just replace

while($row = mysql_fetch_array($run_posts)) {

with

while($row = mysql_fetch_array($run)) {
herr
  • 837
  • 1
  • 8
  • 21