Mysql_fetch_assoc return null values

The code :

<?php 

global $connect;
$connect=  mysqli_connect('localhost', 'root','','andreas');
if (!$connect){
    die('FAILED'. mysqli_error($connect));
 }
                     
                    
                     $the_post_id='46';
                    
                     $query="SELECT * FROM posts WHERE post_id=$the_post_id ";
                     $select_posts_by_id= mysqli_query($connect, $query);
                    
                     while($row= mysqli_fetch_assoc($select_posts_by_id)){
                     
                     
                     $post_title=$_row['post_title'];
                     $post_keimeno=$_row['post_keimeno'];
                     $post_publisher=$_row['post_publisher'];
                     $post_cat_title=$_row['post_cat_title'];
                     $post_image=$_row['post_image'];
                     $post_date= $_row['post_date'];
                     
                     }
   var_dump($the_post_id);   var_dump($select_posts_by_id);  var_dump($row); var_dump($post_title);
                    
                      
        ?>	

The effect:
Notice: Undefined variable: _row in C:\xampp\htdocs\newstheme\admin\includes\test.php on line 18

Notice: Undefined variable: _row in C:\xampp\htdocs\newstheme\admin\includes\test.php on line 19

Notice: Undefined variable: _row in C:\xampp\htdocs\newstheme\admin\includes\test.php on line 20

Notice: Undefined variable: _row in C:\xampp\htdocs\newstheme\admin\includes\test.php on line 21

Notice: Undefined variable: _row in C:\xampp\htdocs\newstheme\admin\includes\test.php on line 22

Notice: Undefined variable: _row in C:\xampp\htdocs\newstheme\admin\includes\test.php on line 23
string(2) “46” object(mysqli_result)#2 (5) { [“current_field”]=> int(0) [“field_count”]=> int( 8) [“lengths”]=> NULL [“num_rows”]=> int(1) [“type”]=> int(0) } NULL NULL

What happens?
Thanks a lot.

Is your variable $row as in while($row= mysqli_fetch_assoc($select_posts_by_id)){ or $_row as in $post_title=$_row['post_title'];? Note the difference between the two.

1 Like

I have $row thanks a lot

You have used undefined variable $_row , try to replace with $row.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.