Use of undefined constant name - assumed 'name' in …的异常,代码如下
程序员文章站
2024-01-18 11:16:34
...
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]添加成功!
";
}
}
}
红字表示的是数据库中表的字段名
------解决方案--------------------
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"]);相关文章
相关视频
推荐阅读