Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从数据库检索post数据时未显示_Php_Html_Mysql - Fatal编程技术网

Php 从数据库检索post数据时未显示

Php 从数据库检索post数据时未显示,php,html,mysql,Php,Html,Mysql,我试图从数据库中检索数据,修复了错误消息,但仍然没有显示数据(帖子id取决于我单击的帖子)。另外,我知道有些变量没有显示出来,我正在将所有的东西放在适当的位置,只是我放置的东西没有显示出来。还有一个数据库连接,只是我不会显示整个文件,因为它太大了 给出问题的函数的代码: function single_post(){ 如果(isset($\u GET['post\u id'])){ 全球$con; $get\u id=$\u get['post\u id']; $get_posts=“从post

我试图从数据库中检索数据,修复了错误消息,但仍然没有显示数据(帖子id取决于我单击的帖子)。另外,我知道有些变量没有显示出来,我正在将所有的东西放在适当的位置,只是我放置的东西没有显示出来。还有一个数据库连接,只是我不会显示整个文件,因为它太大了

给出问题的函数的代码:

function single_post(){
如果(isset($\u GET['post\u id'])){
全球$con;
$get\u id=$\u get['post\u id'];
$get_posts=“从post_id='get_id'”所在的帖子中选择*;
$run\u posts=mysqli\u查询($con,$get\u posts);
$row_posts=mysqli_fetch_数组($run_posts);
$post_id=$row_posts['post_id'];
$user_id=$row_posts['user_id'];
$post_content=$row_posts['post_content'];
$post_content2=$row_posts['post_content2'];
$price=$row_posts['price'];
$pclass=$row_posts['pclass'];
$specificclass=$row_posts['specificclass'];
$upload_image=$row_posts['upload_image'];
$post_date=$row_posts['post_date'];
$user=“从用户中选择*,其中user\u id='$user\u id'和posts='yes';
$run\u user=mysqli\u查询($con,$user);
$row\u user=mysqli\u fetch\u数组($run\u user);
$user\u name=$row\u user['user\u name'];
$user\u image=$row\u user['user\u image'];
如果(isset($\u GET['post\u id'])){
$post\u id=$\u GET['post\u id'];
}
$get_posts=“从用户中选择post_id,其中post_id='$post_id'”;
$run\u user=mysqli\u query($con,$get\u posts);
$post\u id=$\u GET['post\u id'];
$post=$\u GET['post\u id'];
$get_user=“从post中选择*,其中post_id='$post';
$run\u user=mysqli\u查询($con,$get\u user);
$row=mysqli\u fetch\u数组($run\u user);
$p_id=$row['post_id'];
如果($p\u id!=$post\u id){
回显“警报(‘错误’)”;
}
否则{
回声“
产品信息:
产品名称:$post\u content


信息:$post_content 2


Precio向一个异教徒发表演讲:$price


类别:$pclass


子类别:$specificclass


"; } } }
get\u id的代码中存在打字错误

  $get_posts = "select * from posts where post_id='get_id'";
应该是

  $get_posts = "select * from posts where post_id='$get_id'";
关于安全性,请清理您的$\u GET value

如果始终为数字格式,请使用

 is_numeric 
检查一下

例如

 if (isset($_GET['post_id'])) {
   $get_id = sanitized($_GET['post_id']); // sanitize with your created code for it....
   if(is_numeric($get_id)){
    global $con;
      // $get_id = $_GET['post_id']; no need of it as we havev declared it above
    $get_posts = "select * from posts where post_id='$get_id'";
       //..... rest code.....




  }else{

 // show error regarding get id.. like not found etc..

  }

我的投票是一个打字错误;您在
where post\u id='get\u id'
中遗漏了
$
 if (isset($_GET['post_id'])) {
   $get_id = sanitized($_GET['post_id']); // sanitize with your created code for it....
   if(is_numeric($get_id)){
    global $con;
      // $get_id = $_GET['post_id']; no need of it as we havev declared it above
    $get_posts = "select * from posts where post_id='$get_id'";
       //..... rest code.....




  }else{

 // show error regarding get id.. like not found etc..

  }