Rumah > Artikel > pembangunan bahagian belakang > 这个php文件哪里异常,居然无法运行,这是书本配套的代码啊抓狂
这个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 />?>
<!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>