dongxiezhuo8852 2014-09-04 09:19
浏览 38

未定义的变量: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>
  • 写回答

3条回答 默认 最新

  • dongping4901 2014-09-04 09:24
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口