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

WBOY
Release: 2016-06-13 12:00:12
Original
868 people have browsed it

这个php文件哪里错误,居然无法运行,这是书本配套的代码啊。抓狂
config.php 文件 数据库用户名和密码是正确的。

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


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

------解决方案--------------------
 在连接数据库的函数前 加一个@  屏蔽错误。  因为在php中 第一次连接数据库是报错的,  程序从上往下执行,会初始化数据库。导致链接出问题。
------解决方案--------------------
你打开 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