2017-12-31 43 views
-2

에서 검색이 코드PHP : mysqli

<html> 
<body style="background-color: azure"> 
    please import your search request: 
    <br> 
    <form method="get" action="searchprocess.php"> 
     <input type="text" placeholder="please import here" name="search"> 
     <input type="submit"> 
    </form> 
</body> 
</html> 

와 search.php 페이지를 가지고 있고 searchprocess.php 내가 WAMP이 있고 문제가

<?php 
require_once 'functions.php'; 
$search=$_GET['search']; 
$search = preg_replace("#[^0-9a-z]i#","", $search); 

$query="Select * from names where firstname LIKE '%$search%'"; 

$result=mysqli_query($connection,$query); 
$count =mysqli_num_rows($result); 
var_dump($result); 
if ($count == 0) 
{ 
    $output = "there is noting to show you ... sorry search another thing <a href='search.php'>back to search page</a>"; 
    echo $output; 
} 

else{ 
    echo "<table>"; 
    while($row = mysqli_fetch_array($result)){ 
     $id = $result['id']; 
     $firstname = $result['firstname']; 
     $lastname = $result['lastname']; 
     echo '<tr>'; 
     echo '<td>'.$id.'</td>'; 
     echo '<td>'.$firstname.'</td>'; 
     echo '<td>'.$lastname.'</td>'; 
     echo '</tr>'; 


    } 
    echo "</table>"; 

} 

?> 

아래에 내 코드를 시도 할 때입니다입니다 아래 라인의 오류가 발생했습니다.

$id=$row['id']; 
+0

무엇이 오류입니까? [How to Ask] (https://stackoverflow.com/help/how-to-ask)를 확인하고 질문을 편집하십시오. 모두를 도울 것입니다. – Jeffrey

+0

이것은 간단한 오타입니다. – Akintunde007

답변

0

잘못된 var.

while($row = mysqli_fetch_array($result)){ 
    $id = $result['id']; 
    $firstname = $result['firstname']; 
    $lastname = $result['lastname']; 

은 다음과 같아야합니다

while($row = mysqli_fetch_array($result)){ 
    $id = $row['id']; 
    $firstname = $row['firstname']; 
    $lastname = $row['lastname']; 

내가 SQL 주입 공격을 피하기 위해 prepared statements를 사용하는 것이 좋습니다.