Home  >  Article  >  Backend Development  >  php-ajax 从页面中获取元素传递给PHP 进行数据库查询的问题

php-ajax 从页面中获取元素传递给PHP 进行数据库查询的问题

WBOY
WBOYOriginal
2016-06-02 11:28:08923browse

ajaxphp数据库

ajax从界面中获取id为username的文本内容“张三”

<code> $.ajax({            type:"POST",            url:"getallleads.php",            data:"account="+$("#username").text(),            success:function(data){showalllead(data);}        })</code>

PHP中接收,并查询的语句如下:

<code>  $account=$_POST["account"];  echo  "$account";  echo gettype($account);  $result = $conn->query("select * from allsalesleads where 销售人员 like '%".$account."%'");</code>

结果能够echo出account 内容为‘张三’ 数据类型为string 但没有查询结果

然后我直接在在如下PHP中给account赋值 张三,可以查询出。account前后的数据类型都是string

<code>  $account=$_POST["account"];  echo  "$account";  echo gettype($account);  $account='张三';echo gettype($account);  $result = $conn->query("select * from allsalesleads where 销售人员 like '%".$account."%'");</code>

然后我想难道前后两个account不一样吗?
然后
if ($account=="张三") 来进行判断,结果还真不一样,这是咋回事啊?

有什么解决办法吗?非常感谢!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn