【问题标题】:php pdo where request does not function for the giving value?php pdo 请求对给定值不起作用的地方?
【发布时间】:2018-06-26 21:44:33
【问题描述】:

我是 php 和 ajax 的新手,我希望一旦用户选择了一个名称,我就可以从 BDD 中获取具有此名称值的行。我为此使用了使用过的 Jquery 帖子:

这是我的 BDD 请求:

public static function getIdPre($nomp) //My problem is on this $nomp var
{
  require_once('database.php');
  $db = DbConnection::get();
  $prestQuer = $db->prepare('SELECT * FROM prst WHERE nomp=? ');
  $prestQuer->execute(array($nomp));
  $row= $prestQuer->fetch();
  return($row['idp']);
}

这是我获得 $nomp 价值的地方:

 if((isset($_POST['nompr']))){
       $nomp=$_POST['nompr'];
      $FilterTarifs=MainController::getPrstFilterTarif($nomp);
      foreach ($FilterTarifs as $FilterTarif) {
    ...}

一旦我做了这样的事情:

$FilterTarifs=MainController::getPrstFilterTarif('Octroi'); It works perfectly but once I let it in the first way :

$FilterTarifs=MainController::getPrstFilterTarif($nomp);

即使该值是从 Jquery 帖子中正确获取的,它也不起作用:

    $("#filtrBtn").click(function () {
     if(nompres===undefined)
     {
       alert("Choisir un filtre d'abord ");
     }
     else
     {
       $(".bnqInfos").html("");
       $.post(basUrl+'views/component/filterdata.php',
         {
           nompr:nompres,//Here is the given name
         }, function(data) {
          // alert(data);
            $(".bnqInfos").html(data);
        });
     }
  });

这是我的控制器函数 getIdPre():

  public static function getPrstFilterTarif($nomp)
    {
      $idpr=Prest::getIdPre($nomp);
      $result=Tarif::getTarifFilter($idpr);
      return $result;
    }

我不明白为什么它不起作用。 我该怎么办?有人可以帮忙吗。

【问题讨论】:

  • 显示你是如何打电话给getIdPre()的。
  • 这里是: public static function getPrstFilterTarif($nomp) { $idpr=Prest::getIdPre($nomp); $result=关税::getTarifFilter($idpr);返回$结果; }
  • 把它放在问题中,而不是评论。
  • 如果你把var_dump($nomp); 放在getIdPre() 中,它会显示正确的值吗?
  • 你的意思是做这样的事情:$idpr=Prest::getIdPre(var_dump($nomp));结果是:C:\wamp\www\Mini_Prj\controllers\mainController.php:25:string 'Octroi' (length=7)

标签: php jquery mysql ajax pdo


【解决方案1】:

确保$nomp 周围没有多余的空格。

$nomp = trim($_POST['nomp']);

【讨论】:

  • 我的上帝保佑你救了我的命。我找到了解决方案,我已经发布了。非常感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-03-23
  • 1970-01-01
  • 1970-01-01
  • 2013-01-03
  • 2011-02-11
  • 2014-09-27
相关资源
最近更新 更多