0

各製品の編集と削除の 2 つのリンクと共に、製品のリストを表示するフォームを作成しました。

php コードの list_recorder.php ページを参照してください...

<?php
$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password="xxx"; // Mysql password 
$db_name="shopone"; // Database name 
$tbl_name="product"; // Table name 

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("shopone")or die("cannot select DB");

$sql="SELECT * FROM product";
$result=mysql_query($sql);
?>

<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>
<table width="400" border="1" cellspacing="0" cellpadding="3">
<tr>
<td colspan="4"><strong>List data from mysql </strong> </td>
</tr>

<tr>
<td align="center"><strong>product name</strong></td>
<td align="center"><strong>category</strong></td>
<td align="center"><strong>retial price</strong></td>
<td align="center"><strong>price</strong></td>
<td align="center"><strong>detail</strong></td>
</tr>

<?php
while($rows=mysql_fetch_array($result)){
?>

<tr>
<td><?php echo $rows['product_name']; ?></td>
<td><?php echo $rows['product_category']; ?></td>
<td><?php echo $rows['product_retail_price']; ?></td>
<td><?php echo $rows['product_price']; ?></td>
<td><?php echo $rows['product_detail']; ?></td>


<td align="center"><a href="update.php?product_id=<? echo $rows['product_id']; ?>">update</a></td>
</tr>

<?php
}
?>

</table>
</td>
</tr>
</table>

<?php
mysql_close();
?>

このリストはうまく機能しています。次のステップは、製品情報を変更できるように編集することです..

update.phpページと呼ばれる編集コードページを参照してください

<?php
$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password="xxx"; // Mysql password 
$db_name="shopone"; // Database name 
$tbl_name="product"; // Table name 

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("shopone")or die("cannot select DB");

$sql="SELECT * FROM product";
$result=mysql_query($sql);
?>

<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>
<table width="400" border="1" cellspacing="0" cellpadding="3">
<tr>
<td colspan="4"><strong>List data from mysql </strong> </td>
</tr>

<tr>
<td align="center"><strong>product name</strong></td>
<td align="center"><strong>category</strong></td>
<td align="center"><strong>retial price</strong></td>
<td align="center"><strong>price</strong></td>
<td align="center"><strong>detail</strong></td>
</tr>

<?php
while($rows=mysql_fetch_array($result)){
?>

<tr>
<td><?php echo $rows['product_name']; ?></td>
<td><?php echo $rows['product_category']; ?></td>
<td><?php echo $rows['product_retail_price']; ?></td>
<td><?php echo $rows['product_price']; ?></td>
<td><?php echo $rows['product_detail']; ?></td>


<td align="center"><a href="update.php?product_id=<? echo $rows['product_id']; ?>">update</a></td>
</tr>

<?php
}
?>

</table>
</td>
</tr>
</table>

<?php
mysql_close();
?>

list_recorder.php ページを実行し、リストから編集リンクの 1 つを押すと、エラーが表示されます。

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\VertrigoServ\www\shopone\admin\cd\update.php on line 19

$rows=mysql_fetch_array($result); に関連するものです。このエラーの意味がわかりません。どうすれば解決できますか。

助けてくださいありがとう。

午前

4

2 に答える 2

0

クエリをデバッグして、手動で確認してください...クエリが失敗している可能性があるため、スクリプトを少し変更することをお勧めします

$con=mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("shopone", $con)or die("cannot select DB");

すべてがうまくいく場合は試してみてください。

于 2013-10-15T05:21:43.060 に答える
0

$result を渡すたびに次のことを試してください。

$result=mysql_query($sql) or die($sql."<br/><br/>".mysql_error());

これにより、考えられる解決策につながるエラーが表示されます。

次に、次の行を見てください。

<td align="center"><a href="update.php?product_id=<? echo $rows['product_id']; ?>">update</a></td>

開始タグを に変更し、それがデータベース内の有効な列フィールドである<?phpことを確認してください。product_id

于 2013-10-15T05:07:36.140 に答える