这个php文件哪里错误,居然无法运行,这是书本配套的代码啊。抓狂

WBOY
Release: 2016-06-23 13:55:20
Original
992 people have browsed it

config.php 文件 数据库用户名和密码是正确的。

<?phperror_reporting(E_ALL & ~E_NOTICE);$dbhost = 'localhost';$dbuser = 'root';$dbpass = 'password123';$dbname = 'chap2';header('content-type:text/html; charset=gbk');mysql_connect($dbhost, $dbuser, $dbpass);mysql_select_db($dbname);mysql_query('SET NAMES gbk');?>
Copy after login


chap2.php的代码如下: 运行显示空白,到底哪里错了???
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=GBK"><title>我的书架</title><style type="text/css">a {	text-decoration: none;}body {	text-align: center;}#wrap{	text-align: left;	margin: 0 auto;	width: 800px;}</style></head><body><div id="wrap"><center><h2>我的书架</h2></center><?phprequire_once 'config.php';$bookid = $_GET['edit'];if ($_POST['submit']) {$title = $_POST['title'];$author = $_POST['author'];$dateline = $_POST['dateline'];$price = $_POST['price'];$setSQL = "bookid='$bookid',title='$title',author='$author',dateline='$dateline',price='$price'";$sql = $bookid ? "UPDATE books SET $setSQL WHERE bookid='$bookid'" : "INSERT INTO books SET $setSQL";mysql_query($sql);header('location:?');exit;}if ($bookid) {$rs = mysql_query("SELECT * FROM books WHERE bookid='$bookid'");$book = mysql_fetch_assoc($rs);}if ($delid = $_GET['del']) {mysql_query("DELETE FROM books WHERE bookid='$delid'");}$rs = mysql_query("SELECT * FROM books");echo '<h3>图书列表</h3><table width="100%" cellspacing="0" cellpadding="1" border="1" bordercolor="#999"><tr><th>ID</th><th>书名</th><th>作者</th><th>出版时间</th><th>定价</th><th>操作</th></tr>';while ($item = mysql_fetch_assoc($rs)) {	echo "<tr align=\"center\"><td>$item[bookid]</td><td align=\"left\">$item[title]</td><td>$item[author]</td><td>$item[dateline]</td><td>$item[price]</td><td><a href=\"?edit=$item[bookid]\">修改</a> <a href=\"?del=$item[bookid]\">删除</a></td></tr>";}echo '</table>';echo '<h3>' . ($bookid ? '修改图书' : '新增图书') . '</h3>';?><form method="POST"><table cellspacing="0" cellpadding="1" border="0"><tr><td>书名</td><td><input type="text" name="title" value="<?=$book['title']?>"/></td></tr><tr><td>作者</td><td><input type="text" name="author" value="<?=$book['author']?>"/></td></tr><tr><td>出版时间</td><td><input type="text" name="dateline" value="<?=$book['dateline']?>"/></td></tr><tr><td>定价</td><td><input type="text" name="price" value="<?=$book['price']?>"/></td></tr><tr><td colspan="2"><input type="submit" name="submit" value="提交"/> <input type="reset" value="重置"/><?php if ($bookid) {?><a href="?edit=0">取消修改</a><? } ?></td></tr></table></form></div></body></html>
Copy after login


回复讨论(解决方案)

81 行
取消修改 php } ?>

请打开 php 的错误显示功能!
本来是不需要问的

 在连接数据库的函数前 加一个@  屏蔽错误。  因为在php中 第一次连接数据库是报错的,  程序从上往下执行,会初始化数据库。导致链接出问题。

81 行
取消修改 php } ?>

请打开 php 的错误显示功能!
本来是不需要问的


你好,我开启了简短风格就没问题了,但是添加图书,总是无法添加到数据库,看不出哪里有问题。请指点。

你打开 php 的错误显示功能
php.ini 中 display_errors = On

这样只要是程序错误,就会在页面中显示出来
不要自己难为自己

你打开 php 的错误显示功能
php.ini 中 display_errors = On

这样只要是程序错误,就会在页面中显示出来
不要自己难为自己


我确实开启了,这个功能还真不错,不过我还是无法添加上书到数据库,也没有任何错误
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template