查询中的错误或post方法

时间:2017-09-29 11:05:43

标签: php sql

我收到 $ id ='S%'的结果,但收到 $ id = $ id。'%'的结果 $ id = 's'邮寄

$id = $_POST['user_data'];
if($_POST['user_data'].lenght<2)
   { 

       $query = "SELECT id, oauth_provider, first_name, last_name, email, phone, STATUS , picture, link, createdFROM users WHERE first_name LIKE ? ORDER BY id DESC " ;
       $id = $id.'%';
       echo ''.$id; 
         $stmt = $conn->prepare($query);
         $stmt->bind_param('s', $id);
         $stmt->execute();
          $result = $stmt->get_result();
          echo $result->num_rows;
   }

我已经收到了$ id = s的帖子也通过echo它来检查它。 id = $ id ='S%'时输出:  9 id = $ id = $ id。'%'时输出:  0

1 个答案:

答案 0 :(得分:-1)

您的查询似乎有误,应该是

$ query =&#34; SELECT id,oauth_provider,first_name,last_name,email,phone,STATUS,picture,link,created FROM users WHERE first_name LIKE? ORDER BY id DESC&#34; ;

这是一个解决方法

$variable = mysql_real_escape_string($id); $query = "SELECT id, oauth_provider, first_name, last_name, email, phone, STATUS , picture, link, created FROM users WHERE first_name LIKE '% $variable' ORDER BY id DESC";