2017-12-31 50 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が

<?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>"; 

} 

?> 

を下回っている、私はそれはです私のコードをしようとすると、WAMPと問題がある持っています下の行のエラー

$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を使用することをお勧めします。

関連する問題