Notice: Undefined index: post_catagory in /Users/darceymckelvey/Desktop/php/includes/classinsert.php on line 9
Notice: Undefined variable: category in /Users/darceymckelvey/Desktop/php/includes/classinsert.php on line 13
代码:
<?php
require_once('classdb.php');
if(!class_exists('INSERT')){
class INSERT {
public function post($postdata){
global $db;
$catagory = serialize($postdata['post_catagory']);
$query = "
INSERT INTO posts(post_title, post_content, post_category)
VALUES ('$postdata[post_title]', '$postdata[post_content]', '$category')
";
return $db->insert($query);
}
}
}
$insert = new INSERT;
?>
问题:
输出的结果是post_title
和post_content
正在工作,但post_category
完全没有,并且留空。
答案 0 :(得分:1)
您犯了一个错误,您的代码中存在拼写错误,因为您没有获得类别值。
试试这段代码:
<?php
require_once('classdb.php');
if(!class_exists('INSERT')){
class INSERT {
public function post($postdata){
global $db;
$category = serialize($postdata['post_category']);
$query = "
INSERT INTO posts(post_title, post_content, post_category)
VALUES ('$postdata['post_title']', '$postdata['post_content']', '$category')
";
return $db->insert($query);
}
}
}
$insert = new INSERT;
?>