php - Why are these MySQL errors coming up? -


<?php     require_once 'init.php';      $selectpost = mysql_query("         select           posts.id,           posts.author,           posts.posttext          posts          group posts.id     ");     while($row = mysqli_fetch_object($selectpost)) { //line 30          $posts[] = $row;         } ?>  <?php foreach($posts $post): ?> //line 37      <div class="post row">      <p><?php echo $post->author; ?> said: </p>      <p><?php echo $post->posttext; ?></p>     </div>  <?php endforeach; ?> 

i trying display posts database. code have written far. reason getting these errors:

warning: mysqli_fetch_object() expects parameter 1 mysqli_result, boolean given in posts.php on line 30

notice: undefined variable: posts in posts.php on line 37

warning: invalid argument supplied foreach() in posts.php on line 37

i have commented on appropriate lines.

you mixing mysql & mysqli.it should mysqli_query instead of mysql_query if using mysqli. missing connection object -

$selectpost = mysqli_query($conn, "         select           posts.id,           posts.author,           posts.posttext         posts         group posts.id    "); 

mysqli


Comments