doutou7740 2013-01-03 16:31
浏览 13
已采纳

$ _GET没有传递给SELECT查询

I have page with a hyper link on it like so :

preview

When clicking on the A0000000 it will redirect you to localhost/student.php?anum=A00000000

I have checked if the actual number was being passed using

$get = $_GET['anum'];
echo $get;

this is what I get : Preview

I have done this multiple times before but the one thing that has changed is that now I am using a inner join and WHERE clauses to make a specific search. What this search must do is :

  1. List a student that has counselorname as NOT NULL
  2. Where finished= 1
  3. And where the anum or student id number is = to the url anum using $_GET['anum']

this is the select statement :

$anum = filter_input(INPUT_GET, 'anum', FILTER_SANITIZE_STRING);
$anum = filter_var($anum, FILTER_SANITIZE_NUMBER_INT);

    try 
    {
    $query = $dbh->prepare("SELECT * FROM inoffice INNER JOIN comments ON 
                            inoffice.id = comments.id WHERE counselorname 
                            IS NOT NULL AND finished = '1' AND anum = :anum ");
    $query->bindParam(':anum', $anum);
    $query->execute();
    $result = $query->fetchall();
    }
        catch (PDOException $e) {
        error_log($e->getMessage());
        die($e->getMessage());
        }

I have tried the same query just by putting anum = A0000000 and it works flawlessly.

but when i try to do the above code i get an empty echo'd table.

Any help would be awesome! - ty

EDIT 1 : Thank you to cryptic remove the sanitizing part of the code the filter and what not and all works well. That was removing the A from the actual number part. So the query was not passing.

  • 写回答

2条回答 默认 最新

  • duanhongxian6982 2013-01-03 16:34
    关注
    $anum = filter_var($anum, FILTER_SANITIZE_NUMBER_INT);
    

    is stripping out the letter 'A'

    Per the documentation:

    FILTER_SANITIZE_NUMBER_INT - Remove all characters except digits, plus and minus sign.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊