Hello,
i am new to php and from this project i have started my php learning so first of sorry if my question is simple to ask but its difficult for me to understand the error and i want to learn php so i really need from all php expert available here.

so i am getting error in generating news or latest post.. here is my code

<?
include("includes/connect.php");
$select_posts = "select * from posts order by rand() LIMIT 0,2";
$run_posts = mysql_query($select_post);

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

$title = $row ['post_title'];
$date = $row ['post_date'];
$author = $row ['post_author'];
$image = $row ['post_image'];
$content = substr($row ['post_content'],0,200);+
}
?>

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

Following i am getting in my news page :

Notice: Undefined variable: title in G:\wamp\www\rect\includes\news_data.php on line 16

Try this:

<? php
  include("includes/connect.php");
  $select_posts = "select * from posts order by rand() LIMIT 0,2";
  $run_posts = mysql_query($select_post);
  while($row=mysql_fetch_array($run_post)){
      $title = $row ['post_title'];
      $date = $row ['post_date'];
      $author = $row ['post_author'];
      $image = $row ['post_image'];
      $content = substr($row ['post_content'],0,200);
  }
  echo "<h2>".$title."</h2>";
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.