我有一個從數據庫獲取SKU並創建頁面的頁面。示例網址:http://example.com/index.php?sku=1234567PHP動態頁面無法正常工作
當我加載一個這樣的URL時,它什麼都不顯示 - 甚至連我用echo
輸出的表都沒有。下面是我的代碼:
$sku = $_GET['sku'];
$result = mysqli_query($conn, "SELECT productname, price, producturl, productimg, productdesc, sku FROM table WHERE sku=" . $sku);
while ($row = mysqli_fetch_array($result)) {
echo '<h3>test</h3>';
echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><h4>'.$row["sku"].'</h4></td>
<td><h3>'.$row["productname"].'</h3></td>
<td rowspan="2"><img src="'.$row["productimg"].'" width="100%" alt="productimg"/></td>
</tr>
<tr>
<td colspan="2" rowspan="2"><p>'.$row["productdesc"].'</p></td>
</tr>
<tr>
<td><a class="button" href="'.$row["producturl"].'">View Product</a> <a class="alert button" href="">No Match</a> <a class="alert button" href="">Match</a></td>
</tr>
</table>';
}
我已經連接到我的數據庫,並具有<?php
和?>
標籤在那裏。 - 只是表
while ($row = mysqli_fetch_array($result)) {
,也拆除收盤}
,它的工作原理,但不顯示任何數據:我雖然玩了,如果我刪除此行注意。我不確定這裏發生了什麼事。
你可以試試這個: $結果= mysqli_query($康恩,「選擇產品名稱,價格,PRODUCTURL,productimg,productdesc,SKU FROM表WHERE SKU = '$ SKU'); – Maximus2012
echo mysqli_num_rows($ result)。「記錄發現...「; – steven
您的代碼易受** SQL注入**,請閱讀此:http://stackoverflow.com/questions/60174/how-to-prevent-sql-injection-in-php – Mansfield