【问题标题】:Executing mysqli_query works but it does not return exact row given in WHERE CLAUSE执行 mysqli_query 有效,但它不返回 WHERE CLAUSE 中给出的确切行
【发布时间】:2019-03-25 12:29:30
【问题描述】:

查询执行.. 但是假设用户更改了 $_GET['sub'] 的值以获取不在数据库中的 id,例如:60。 它应该打印“未找到”而不是打印找到!这是为什么呢?

 $main = new  MainClass();

 $subid = mysqli_real_escape_string($main->MsqlConRes,$_GET['sub']);

if (is_numeric($subid))
{
    $main->query = mysqli_query($main->MsqlConRes,"SELECT * FROM subjects WHERE id = ".$subid."") or die(mysqli_error());
    if ($main->query)
    {
        echo'Found';
    }
    else
        echo'Not Found !';
}
else
    $main->errors(404);

【问题讨论】:

  • user edited the $_GET['sub'] -> 基本上这意味着用户编辑预先存在的记录
  • 我的意思是来自 URL 的子值!示例:index.php?sub=id

标签: php oop mysqli


【解决方案1】:

if 中使用mysqli_num_row()

if (mysqli_num_row($main->query)>0)
    {
        echo'Found';
    }
    else
        echo'Not Found !';

由于查询正确执行,所以if ($main->query) 将始终为真

【讨论】:

  • 谢谢你成功了!我正在寻找的那个功能!
猜你喜欢
  • 2019-11-23
  • 2019-11-01
  • 2015-02-12
  • 2023-03-22
  • 2015-11-10
  • 2013-07-04
  • 2020-12-17
  • 1970-01-01
  • 2012-07-14
相关资源
最近更新 更多