2017-09-15 1 views
0

저는 여기에 새로운데 페이지에 표시하지 않고 데이터를 필터링하는 데 문제가 있습니다. 오류가 발생하여 도와주세요. 나쁜 영어에 대해 유감스럽게 생각합니다.데이터 필터링 오류가 발생했습니다.

오류 : 페이지가로드 if(isset($_POST['submit']))이 거짓 일 때 때문에이 오류가 발생하는

Notice: Undefined variable: search_result in /storage/ssd3/688/2645688/public_html/test.php on line

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /storage/ssd3/688/2645688/public_html/test.php on line

<?php 
 
if(isset($_POST['submit'])) 
 
{ 
 
    $valueToSearch = $_POST['search']; 
 

 
$query = "SELECT * FROM `login` WHERE CONCAT(`id`, `username`, `password`) LIKE '%".$valueToSearch."%'"; 
 
    $search_result = filterTable($query); 
 
    
 
} 
 

 
function filterTable($query) 
 
{ 
 

 
$connect= mysqli_connect("localhost","root","","cable"); 
 
$filter_Result = mysqli_query($connect, $query); 
 
    return $filter_Result; 
 
} 
 

 
?> 
 
<form action="test.php" method="POST"> 
 
<div class="container"> 
 
\t <div class="row"> 
 
     <br><br><div class="search"> 
 
<input type="text" name="search" class="form-control input-sm" maxlength="64" placeholder="Search" /> 
 
<button type="submit" name="submit" class="btn btn-primary btn-sm">Search</button> 
 
</div> 
 
\t </div> 
 
</div> 
 
</br></br> 
 
</form> 
 

 
<table> 
 
       <tr> 
 
        <th>Id<br></th> 
 
        <th>Username:</th> 
 
        <th>Password</th> 
 
        </tr> 
 
              <?php while($row = mysqli_fetch_array($search_result)):?> 
 

 
       <tr> 
 
        <td><?php echo $row['id'];?><br></td> 
 
        <td><?php echo $row['username'];?></td> 
 
        <td><?php echo $row['password'];?></td> 
 
        
 
       </tr> 
 
       <?php endwhile;?> 
 
      </table>

+1

가 없을 수 있습니다 상단에있는 기능을 넣어 것을 염두에 보관해야합니다. 친절하게 $ connect를 filterTable ($ connect, $ query)에 추가하십시오. –

답변

0

그러므로 $search_result = filterTable($query);하지가 실행을 수행하고, 따라서 mysqli_fetch_arrayNULL을 가져옵니다. 해결책은 간단하다

, 우리는 페이지가로드에서 더 $search_result

<?php 
$search_result = NULL; 

if(isset($_POST['submit'])) 
{ 
    $valueToSearch = $_POST['search']; 
    $query = "SELECT * FROM `login` WHERE CONCAT(`id`, `username`, `password`) LIKE '%".$valueToSearch."%'"; 
    $search_result = filterTable($query); 
} 

function filterTable($query) 
{ 
    $connect= mysqli_connect("localhost","root","","cable"); 
    $filter_Result = mysqli_query($connect, $query); 
    return $filter_Result; 
} 

?> 
<form action="test.php" method="POST"> 
<div class="container"> 
    <div class="row"> 
     <br><br><div class="search"> 
<input type="text" name="search" class="form-control input-sm" maxlength="64" placeholder="Search" /> 
<button type="submit" name="submit" class="btn btn-primary btn-sm">Search</button> 
</div> 
    </div> 
</div> 
</br></br> 
</form> 

<table> 
       <tr> 
        <th>Id<br></th> 
        <th>Username:</th> 
        <th>Password</th> 
        </tr> 
              <?php if(!empty($search_result)): while($row = mysqli_fetch_array($search_result)):?> 

       <tr> 
        <td><?php echo $row['id'];?><br></td> 
        <td><?php echo $row['username'];?></td> 
        <td><?php echo $row['password'];?></td> 

       </tr> 
       <?php endwhile; endif; ?> 
      </table> 
+0

이 녀석은 맞다. 페이지를로드 할 때 오류가 발생합니다. $ search_result는 NULL/정의되지 않습니다. –

+0

덕분에 많은 사람. –

+0

@IrfanBashir이 ​​도움이된다면 upvote 또는 답변을 수락하십시오. –

관련 문제