未定义的变量:run_posts和警告:mysql_fetch_array()期望参数1为资源,给定[duplicate]为null

This question already has an answer here:

 <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

</div>

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.

just replace

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

with

while($row = mysql_fetch_array($run)) {
$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)) {