2017-02-25 55 views
0

我一直試圖解決這個問題幾個小時,但仍然沒有進展。想要將我的數據庫結果回覆到在我的html中創建的表格中,但它只是彈出窗口一側。請建議我可以做的事情。謝謝。 enter image description here PHPPHP的回聲表不工作

if (isset($_POST['search'])) { 

    include 'dbh.php'; 
    $uid =$_POST['name1']; 
    $nric = $_POST['nric1']; 
    $number = $_POST['number1']; 

    $sql = "SELECT * FROM user WHERE name = '$uid' OR nric = '$nric' OR contact = '$number' "; 
    $result = $conn->query($sql); 

    if (!$row = mysqli_fetch_assoc($result)) 
    { 
     echo "No result is found! "; 
    } 
    else 
    { 

     echo "result found"; 
     $_SESSION['id'] = $row['id']; 
      echo "<tr>"; 
      echo "<td>".$row['no']."</td>"; 
      echo "<td>".$row['name']."</td>"; 
      echo "<td>".$row['surname']."</td>"; 
      echo "<td>".$row['nric']."</td>"; 
      echo "<td>".$row['contact']."</td>"; 
      echo "<td>".$row['gender']."</td>"; 
      echo "<td>".$row['email']."</td>"; 
      echo "<td>".$row['address']."</td>"; 
      echo "<td>".$row['date']."</td>"; 

      echo "</tr>"; 
    } 

} 

在我的形式方法。

 <!-- Search function aboutus about us website --> 

     <form method="post" action="" > 

     <div class="panel" id="aboutus"> 

     <h1>About Us</h1> 

     <!-- end of header --> 
       <input type="text" name="nric1" 
     placeholder="NRIC"><br> <input type="text" name="name1" 
     placeholder="Name"><br> 
    <input type="text" name="number1" placeholder="Details Number"><br> 
    <table width = "300" border = "1" cellpadding="1" cellspacing="1"> 
    <tr> 
    <th>No</th> 
    <th>Name</th> 
    <th>Surname</th> 
    <th>Nric</th> 
    <th>Contact</th> 
    <th>Gender</th> 
    <th>Email</th> 
    <th>Address</th> 
    <th>Data</th> 
    <tr> 
    </table> 
    <input type="submit" name="search" value="Search"> 
    </form> 

回答

1

當然重要的是,你需要呼應它在適當的位置,裏面的HTML.Assuming的你也有HTML inisde相同的PHP頁面

<form method="post" action="" > 

     <div class="panel" id="aboutus"> 

     <h1>About Us</h1> 

     <!-- end of header --> 
       <input type="text" name="nric1" 
     placeholder="NRIC"><br> <input type="text" name="name1" 
     placeholder="Name"><br> 
    <input type="text" name="number1" placeholder="Details Number"><br> 
    <table width = "300" border = "1" cellpadding="1" cellspacing="1"> 
    <tr> 
    <th>No</th> 
    <th>Name</th> 
    <th>Surname</th> 
    <th>Nric</th> 
    <th>Contact</th> 
    <th>Gender</th> 
    <th>Email</th> 
    <th>Address</th> 
    <th>Data</th> 
    <tr> 
<?php ...else{ 
      $_SESSION['id'] = $row['id']; 
      echo "<tr>"; 
      echo "<td>".$row['no']."</td>"; 
      echo "<td>".$row['name']."</td>"; 
      echo "<td>".$row['surname']."</td>"; 
      echo "<td>".$row['nric']."</td>"; 
      echo "<td>".$row['contact']."</td>"; 
      echo "<td>".$row['gender']."</td>"; 
      echo "<td>".$row['email']."</td>"; 
      echo "<td>".$row['address']."</td>"; 
      echo "<td>".$row['date']."</td>"; 

      echo "</tr>"; 
?> 


    </table> 
    <input type="submit" name="search" value="Search"> 
    </form>