编写的一段PHP的代码,测试的时候始终报错。实在是找不到原因了。求解啊。
这是MYSQL sql数据的表与字段等 :/*
-- phpMyAdmin SQL Dump
-- version 3.2.0.1
-- http://www.phpmyadmin.net
--
-- 主机: localhost
-- 生成日期: 2011 年 04 月 30 日 08:17
-- 服务器版本: 5.5.8
-- PHP 版本: 5.3.3
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
--
-- 数据库: `tushu`
--
-- --------------------------------------------------------
--
-- 表的结构 `td_book`
--
CREATE TABLE IF NOT EXISTS `td_book` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`bookname` varchar(20) NOT NULL,
`issudate` datetime NOT NULL,
`price` double NOT NULL,
`maker` varchar(10) NOT NULL,
`publisher` varchar(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=gb2312 AUTO_INCREMENT=9 ;
--
-- 转存表中的数据 `td_book`
--
INSERT INTO `td_book` (`id`, `bookname`, `issudate`, `price`, `maker`, `publisher`) VALUES
(0, '书1', '2011-04-21 13:14:47', 0, '书1书1书1', '书1书1书1'),
(1, '书2', '2011-04-13 13:14:56', 0, '书1书1书1', '书1书1书1书1');
*/
这是PHP编写的代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="style.css" rel="stylesheet">
<title>应用mysql_fetch_array()函数从数组结果集中获取信息</title>
</head>
<body>
<table width="609" height="134" border="1" cellpadding="0" cellspacing="0" bgcolor="#9E7DB4" align="center">
<form name="myform" method="post" action="">
<tr>
<td width="605" height="51" bgcolor="#CC99FF"><div align="center">请输入图书名称
<input name="txt_book" type="text" id="txt_book" size="25" >
<input type="submit" name="Submit" value="查询">
</div></td>
</tr>
</form>
<tr valign="top" bgcolor="#FFFFFF">
<td height="81">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="79" align="center" valign="top"> <br>
<table width="572" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#625D59">
<tr align="center" bgcolor="#CC99FF">
<td width="46" height="20">编号</td>
<td width="167">图书名称</td>
<td width="90">出版时间</td>
<td width="70">图书定价</td>
<td width="78">作者</td>
<td width="114">出版社</td>
</tr>
<?php
//连接数据库
$link=@mysql_connect("localhost","root","") or die ("数据库连接失败".mysql_error());
mysql_select_db("tushu",$link);
mysql_query("set names gb2312");
//从数组结果集中获取信息
$sql=mysql_query("select * from td_book");
$info=mysql_fetch_array($sql);
//使用if语名判断用户是否单击了查询按钮
if($_POST['submit']=="查询"){
$txt_book=$_post['txt_book'];
//如果选择的条件为"\like",进行模糊查询
$sql=mysql_query("select * from td_book where bookname like '%".trim($txt_book)."%'");
$info=mysql_fetch_array($sql);
}
if($info==flase){
echo"<div align='center' style='color:#ff0000'; font-size:12px'>对不起不存在</div>";
}
do{
?>
<tr align="left" bgcolor="#FFFFFF">
<td height="20" align="center"><?php echo $info[id]; ?></td>
<td > <?php echo $info[bookname]; ?></td>
<td align="center"><?php echo $info[issuDate]; ?></td>
<td align="center"><?php echo $info[price]; ?></td>
<td align="center"> <?php echo $info[maker]; ?></td>
<td> <?php echo $info[publisher]; ?></td>
</tr>
<?php
}
while($info=mysql_fetch_array($sql));
?>
</table></td>
</tr>
</table>
<br></td>
</tr>
</table>
</body>
</html>
这是报错的信息:
Notice: Use of undefined constant id - assumed 'id' in F:\wamp\www\bbs\index.php on line 57 0 | Notice: Use of undefined constant bookname - assumed 'bookname' in F:\wamp\www\bbs\index.php on line 58 书1 | Notice: Use of undefined constant issuDate - assumed 'issuDate' in F:\wamp\www\bbs\index.php on line 59 Notice: Undefined index: issuDate in F:\wamp\www\bbs\index.php on line 59 | Notice: Use of undefined constant price - assumed 'price' in F:\wamp\www\bbs\index.php on line 60 0 | Notice: Use of undefined constant maker - assumed 'maker' in F:\wamp\www\bbs\index.php on line 61 书1书1书1 | Notice: Use of undefined constant publisher - assumed 'publisher' in F:\wamp\www\bbs\index.php on line 62 书1书1书1 |
Notice: Use of undefined constant id - assumed 'id' in F:\wamp\www\bbs\index.php on line 57 1 | Notice: Use of undefined constant bookname - assumed 'bookname' in F:\wamp\www\bbs\index.php on line 58 书2 | Notice: Use of undefined constant issuDate - assumed 'issuDate' in F:\wamp\www\bbs\index.php on line 59 Notice: Undefined index: issuDate in F:\wamp\www\bbs\index.php on line 59 | Notice: Use of undefined constant price - assumed 'price' in F:\wamp\www\bbs\index.php on line 60 0 | Notice: Use of undefined constant maker - assumed 'maker' in F:\wamp\www\bbs\index.php on line 61 书1书1书1 | Notice: Use of undefined constant publisher - assumed 'publisher' in F:\wamp\www\bbs\index.php on line 62 书1书1书1书1 |
追问:Fatal error: Cannot use object of type stdClass as array in F:\wamp\www\www\search.php on line 48
提示错误哦。