时间:2021-07-01 10:21:17 帮助过:29人阅读
error_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');
?>
我的书架 我的书架
require_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 '图书列表
ID | 书名 | 作者 | 出版时间 | 定价 | 操作 |
---|---|---|---|---|---|
$item[bookid] | $item[title] | $item[author] | $item[dateline] | $item[price] | 修改 删除 |