如何修复未定义的变量:在PHP中的u_id通知?

时间:2019-04-04 19:14:15

标签: php sql

我正在尝试通过下面的此功能显示存储在数据库中的帖子,但我正在获取 注意:未定义的变量:u_id

function user_posts($con){

 if(isset($_GET['u_id'])){
 $u_id = $_GET['u_id'];
}

 $get_posts = "SELECT * FROM posts WHERE user_id='$u_id' ORDER BY 1 DESC";

 $run_posts = mysqli_query($con,$get_posts);

 While($row_posts = mysqli_fetch_array($run_posts)){
 $post_id = $row_posts['post_id'];
 $user_id = $row_posts['user_id'];
 $content = $row_posts['post_content'];
 $post_date = $row_posts['post_date'];

 $user = "SELECT * FROM users WHERE user_id='$user_id' AND posts='yes'";

 $run_user = mysqli_query($con,$user);
 $row_user = mysqli_fetch_array($run_user);

 $user_name = $row_user['user_name'];
 $user_image = $row_user['user_image'];

 echo"<br>
 <div id='posts' class='w3-container w3-card w3-white w3-round w3-padding'>
  <p><img src='users/$user_image' width='60' height='60'></p>
  <h4><a style='text-decoration: none;' href='user_profile.php?u_id=$user_id'>$user_name</a>&nbsp<small style='color:#607d8b;'>Posted on $post_date</small></h4><hr>
  <p style='color:#gray;white-space: pre-line;'>$content<span>...</span></p>
  <a href='single.php?post_id=$post_id'>
    <button class='w3-button w3-theme w3-right'>View Post</button>
  </a>
 </div>
 ";
 }

}

我假设变量已经在if(isset)条件中定义

我做错了什么?

0 个答案:

没有答案