为什么我的 ajax 不能从数据库中获取数据?[关闭]

Why can't my ajax fetch data from the database? [closed]

提问人:Samantha Kyle Apostol 提问时间:11/13/2023 最后编辑:ADysonSamantha Kyle Apostol 更新时间:11/13/2023 访问量:37

问:


这个问题似乎与帮助中心定义的范围内的编程无关。

9天前关闭。

当我输入 SYMPTOMS 而不是得到 Illness 时,它会显示 else 语句

<?php
$conn = mysqli_connect("localhost" , "root" , "" , "symptoms");
if (!$conn) {
      die("Connection failed: " . mysqli_connect_error());
  }

$getMesg = mysqli_real_escape_string($conn, $_POST['text']);


$check_data = "SELECT * FROM diagnose2 WHERE Symptoms LIKE '%diagnose2%'";
$run_query = mysqli_query($conn, $check_data) or die("Error");

if(mysqli_num_rows($run_query) > 0){
    
    $fetch_data = mysqli_fetch_assoc($run_query);
    $replay = $fetch_data['Illness'];
    echo $replay;
}else{
    echo "Sorry can't be able to understand you!";
}

$conn->close();

?>

enter image description here

而不是 Sorry can't able to understand you!,显示 Illness

php mysql ajax

评论

1赞 Paul T. 11/13/2023
旁注查询存在SQL注入问题,real_escape_string保障不够!无论如何,对于这个问题,为什么在搜索时重复表名:?...我认为意图应该有:相反?%diagnose2%%$getMesg%
0赞 Paul T. 11/13/2023
当您有时间时,请查看有关已准备好的查询语句的信息,以帮助避免注入问题。
1赞 ADyson 11/13/2023
您未在查询中使用$getMesg

答: 暂无答案