2014-04-23 81 views
0

執行事先準備好的聲明我的代碼如下這是給我編寫的語句行錯誤:得到錯誤在PHP

homepage.php

<html> 
<head> 
</head> 
<body> 
<ul id="list"> 
      <li><h3><a href="#">tops</a></h3></li> 
      <li><h3><a href="#">suits</a></h3></li> 
      <li><h3><a href="#">jeans</a></h3></li> 
      <li><h3><a href="newpage.php?name=women">more</a></h3></li> 
      </ul> 
</body> 
</html> 

newpage.php

<?php 
$mysqli = new mysqli('localhost', 'root', '', 'shop'); 

    if(mysqli_connect_errno()) { 
     echo "Connection Failed: " . mysqli_connect_errno(); 
     } 
?> 
<html> 
<head> 
</head> 
<body> 
<?php 
session_start(); 
$lcSearchVal=$_GET['name']; 
//echo "hi"; 
$lcSearcharr=explode("-",$lcSearchVal); 
$result=count($lcSearchVal); 
//echo $result; 



$parts = array(); 
$parts1=array(); 
foreach($lcSearcharr as $lcSearchWord){ 
    $parts[] = '`PNAME` LIKE "%'.mysqli_real_escape_string($lcSearchWord).'%"'; 
    $parts1[] = '`TAGS` LIKE "%'.$lcSearchWord.'%"'; 
    //$parts[] = '`CATEGORY` LIKE "%'.$lcSearchWord.'%"'; 
} 
$stmt = $mysqli->prepare("SELECT * FROM xml where ('.implode ('AND',?).')"); 
$stmt->bind_Param("s",$parts); 

$list=array(); 
if ($stmt->execute()) { 
    while ($row = $stmt->fetch()) { 
    $list[]=$row; 
    } 
} 


    $stmt->close(); 

    $mysqli->close(); 
foreach($list as $array) 
{ 
?> 
      <div class="image"> 
<img src="<?php echo $array['IMAGEURL']?>" width="200px" height="200px"/></a> 
<?php 
} 
?> 
</div> 
</body> 
</html> 

沒有執行php文件中的SQL查詢。我收到以下錯誤:

mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement

我不能糾正錯誤,我嘗試了很多。

+2

我建議回聲-ING出來的SELECT語句,並張貼了結果,所以我們可以看到放在一起,整個查詢。 – AllisonC

+0

mysqli和mysql混在一起... –

+0

我在打印select語句先生後得到布爾值false。 – user3564442

回答

0

變化

$parts[] = '`PNAME` LIKE "%'.mysql_real_escape_string($lcSearchWord).'%"'; 

$parts[] = '`PNAME` LIKE "%'.mysqli_real_escape_string($lcSearchWord).'%"'; 
+0

我修改它先生,但仍然無法正常工作 – user3564442