2017-05-19 29 views
0

私は単純なhtml/phpスクリプトで忙しく、データベースから検索した結果をテーブル形式で表示しても何も表示されません。 は、ここに私のコードです:私は検索バーに「3」と入力PHPのテーブルに検索結果を表示するには

<html> 
    <head> 
     <title>product sales for a specific customer</title> 
     <link rel="stylesheet" type="text/css" href="css/style.css" /> 
    </head> 
    <body> 
      <h3 align="center"> Please Search for a specific customer you want to see sales for: </h3> 
      <br /> 
      <input type="text" name="txtNameSearch" /> 
      <input class="src_btn" type="submit" name="btnSearch" value="Search" /> 
       <table width="800" border="1" cellpadding="1" cellspacing="1"> 
       <tr> 
       <th>Order Details Id</th> 
       <th>Order ID</th> 
       <th>Product Id</th> 
       <th>Login ID</th> 
       <th>Quantity</th> 
       <th>Product Price per unit</th> 
       <th>Product Name</th> 
       <th>Product Descrp</th> 
       <th>Genre</th> 
       <th>Price</th> 
       <th>Quantity Sold</th> 
       </tr> 
<?php 
if(isset($_POST["btnSearch"])) 
{ 
$connection = mysqli_connect('localhost', 'root', '', 'bookstore'); 
$sql="SELECT * FROM order_details right join tblproduct on order_details.prod_id=tblproduct.prod_id WHERE id_login = $search"; 
$Joined_records=mysqli_query($connection,$sql); 

if (isset($_POST['txtNameSearch'])){ 
    $search = $_POST['txtNameSearch']; 
} 
while ($row=mysqli_fetch_assoc($Joined_records)){ 
    echo"<tr>"; 
    echo"<td>".$row["order_details_id"]."</td>"; 
    echo"<td>".$row["order_id"]."</td>"; 
    echo"<td>".$row["prod_id"]."</td>"; 
    echo"<td>".$row["id_login"]."</td>"; 
    echo"<td>".$row["quantity"]."</td>"; 
    echo"<td>".$row["price_per_unit"]."</td>"; 
    echo"<td>".$row["prod_name"]."</td>"; 
    echo"<td>".$row["prod_descr"]."</td>"; 
    echo"<td>".$row["prod_cat"]."</td>"; 
    echo"<td>".$row["prod_price"]."</td>"; 
    echo"<td>".$row["prod_quan"]."</td>"; 
    echo"</tr>"; 

} 
} 

?> 
    </body> 
</html> 

だから私はやりたいインスタンスのためのものであり、私はで表示する私のデータベースに私はその3に対応するすべての値をしたい提出クリックテーブル形式。

+1

POSTから検索値を取得する前に、SQLインジェクションBTWの影響を受けやすいクエリを実行しています。 –

+0

@MattS私はそれを試みましたが、それでもうまくいきません。 –

+0

@MoeJoe Mattが言っていることは、あなたがデータベースの検索を終えた後、あなたがあなたの '$ search'変数に値を割り当てているということです。それは逆のやり方です。 –

答えて

1

私はあなたのコードで参照してください。

$sql="SELECT * 
    FROM order_details 
    right join tblproduct 
    on order_details.prod_id=tblproduct.prod_id 
    WHERE id_login = $search"; 

は、このSQLの問題をともかく、後でコード内まで$searchを定義していません。これは、あなたが埋め込まれた金庫を含むクエリ文字列を作成前を行う必要がある、それは適切にエスケープする必要がありますし、クエリに引用されている必要があります

$search = "'" . mysqli_real_escape_string(
     $connection, $_POST['txtNameSearch'] 
     ) . "'"; 

また、適切なエラーチェックやハンドリングを追加する必要があります(少なくとも)mysqli_query()呼び出しを行います。

関連する問題