日期:2014-05-17  浏览次数:20442 次

Use of undefined constant name - assumed 'name' in ……的错误,代码如下:
function add_books(){
include_once("class_books.php"); //包含图书类
if($_POST["submit"]=="添加"){
if($_POST["add_book_name"]=="" || $_POST["add_book_price"]=="" || $_POST["add_book_author"]==""){
echo "<font color=red>添加失败,请把信息填写完整</font><br>";
echo "<a href=\"javascript:history.go(-1)\">重试</a>";
}
else{
$b=new books;
$b->__set(name,$_POST["add_book_name"]);
$b->__set(price,$_POST["add_book_price"]);
$b->__set(author,$_POST["add_book_author"]);
$b->add();
echo "图书$_POST[book_name]添加成功!<br>";
}
}
}
红字表示的是数据库中表的字段名

------解决方案--------------------
PHP code

$b->__set(name,$_POST["add_book_name"]); 
$b->__set(price,$_POST["add_book_price"]); 
$b->__set(author,$_POST["add_book_author"]);