Rumah >pembangunan bahagian belakang >tutorial php >Use of undefined constant name - assumed 'name' in …的异常,代码如下
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 "添加失败,请把信息填写完整
";
echo "重试";
}
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]添加成功!
";
}
}
}
红字表示的是数据库中表的字段名
------解决方案--------------------
$b->__set(name,$_POST["add_book_name"]); $b->__set(price,$_POST["add_book_price"]); $b->__set(author,$_POST["add_book_author"]);<div class="clear"> </div>