PHP警告:mysql_num_rows():提供的参数不是有效的MySQL结果资源



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

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

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

connection.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'));
?>

index . 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;
}?>

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

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

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

相关内容

  • 没有找到相关文章

最新更新