1

我正在为库存数据库创建一个 CRUD。加载 index.php 后,我的 error_log 返回以下内容:

PHP 警告:mysql_num_rows():提供的参数不是第 32 行 /home1/theantj4/public_html/crud/index.php 中的有效 MySQL 结果资源

我真的不知道是什么导致了这个错误,但这是我在这里工作的,也许有人可以发现这个问题......

连接.php

<?php
$conn = mysql_connect('localhost','usrname','pwd') or 
die(mysql_error('unable to connect to given database'));

mysql_select_db('theantj4_antique',$conn) or die(mysql_error('unable to select 
database'));
?>

索引.php

<!DOCTYPE HMTL>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Inventory Management Tool</title>
</head>
<body>
<?php require_once('connection.php'); ?>
<?php
$query = mysql_query("SELECT * FROM inventory");
$result = mysql_query($query);
?>
<div id="addinventory"><a href="add.php">Add Contact</a></div>
<table width="540" border="0" cellpadding="3">
<tr style="color:#FF">
<td width="150" bgcolor="#cccccc">itemNumber</td>
<td width="150" bgcolor="#cccccc">itemTitle</td>
<td width="150" bgcolor="#cccccc">itemDate</td>
<td width="150" bgcolor="#cccccc">itemPrice</td>
<td width="150" bgcolor="#cccccc">itemAuthor</td>
<td width="150" bgcolor="#cccccc">itemMedium</td>
<td width="150" bgcolor="#cccccc">itemCondition</td>
<td width="150" bgcolor="#cccccc">itemInches</td>
<td width="150" bgcolor="#cccccc">itemMetric</td>
<td width="150" bgcolor="#cccccc">smallImageName</td>
<td width="150" bgcolor="#cccccc">bigImageName</td>
<td width="150" bgcolor="#cccccc">itemCategory1</td>
<td width="150" bgcolor="#cccccc">itemCategory2</td>
</tr>
<?php
 $i=0;
if(mysql_num_rows($result) > 0) { /*Line 32*/
while($row=mysql_fetch_object($result)) { $i++ ; ?> 

<tr class="box" <?php if($i%2==0) { ?> bgcolor="#C5E8E1" <?php } else { ?>bgcolor="#E2EFD0" <?php } ?>>
<td><?php echo $i; ?></td>
<td><span id="itemNumber-<?php echo $row->itemNumber; ?>" class="editText"><?php echo $row->itemNumber;?></span></td>
<td><span id="itemTitle-<?php echo $row->itemNumber; ?>" class="editText"><?php echo $row->itemTitle;?></span></td>
<td><span id="itemDate<-<?php echo $row->itemNumber; ?>" class="editText"><?php echo $row->itemDate;?></span></td>
<td><span id="itemPrice-<?php echo $row->itemNumber; ?>" class="editText"><?php echo $row->itemPrice;?></span></td>
<td><span id="itemAuthor-<?php echo $row->itemNumber; ?>" class="editText"><?php echo $row->itemAuthor;?></span></td>
<td><span id="itemMedium-<?php echo $row->itemNumber; ?>" class="editText"><?php echo $row->itemMedium;?></span></td>
<td><span id="itemCondition-<?php echo $row->itemNumber; ?>" class="editText"><?php echo $row->itemCondition;?></span></td>
<td><span id="itemInches-<?php echo $row->itemNumber; ?>" class="editText"><?php echo $row->itemInches;?></span></td>
<td><span id="itemMetric-<?php echo $row->itemNumber; ?>" class="editText"><?php echo $row->itemMetric;?></span></td>
<td><span id="smallImageName-<?php echo $row->itemNumber; ?>" class="editText"><?php echo $row->smallImageName;?></span></td>
<td><span id="bigImageName-<?php echo $row->itemNumber; ?>" class="editText"><?php echo $row->bigImageName;?></span></td>
<td><span id="itemCategory1-<?php echo $row->itemNumber; ?>" class="editText"><?php echo $row->itemCategory1;?></span></td>
<td><span id="itemCategory2-<?php echo $row->itemNumber; ?>" class="editText"><?php echo $row->itemCategory2;?></span></td>
<td><a href="edit.php?id=<?php echo $row->itemNumber; ?>">Edit</a> / <a class="delete" id="<?php echo $row->itemNumber; ?>" onclick="return confirm('are you sure you want to delete');" href="#" >Delete</a></td>
</tr>
<?php   } ?>
<?php   } else {
    echo 'There is no Records';
    exit;
}?>
4

1 回答 1

4
$query = mysql_query("SELECT * FROM inventory");
$result = mysql_query($query);

您正在尝试对结果运行查询。应该:

$query = "SELECT * FROM inventory";
$result = mysql_query($query);
于 2011-11-22T19:21:38.163 回答