Home >Backend Development >PHP Tutorial > Use of undefined constant name - assumed 'name' in …的异常,代码如下

Use of undefined constant name - assumed 'name' in …的异常,代码如下

WBOY
WBOYOriginal
2016-06-13 13:29:54936browse

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]添加成功!
";
}
}
}
红字表示的是数据库中表的字段名

------解决方案--------------------

PHP code

$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>
Statement:
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