As a pdo class I use https://github.com/indieteq/PHP-MySQL-PDO-Database-Class this is my insert code. While insert action I get an error ( select functions works with out problems ) I have no ideas how to solve it, thanks for help.
$insert = $db->query("INSERT INTO post (user_id,post_name,color,start_date,expire_date,content,title,status,rate,category,created,changed,target) VALUES (:user_id,:post_name,:color,:start_date,:expire_date,:content,:title,:status,:rate,:category,:created,:changed,:target)", array(
':user_id' => $this->user_id,
':post_name' => $this->post_name(),
':color' => $params['color'],
':start_date' => $params['start_date'],
':expire_date' => $expDate,
':content' => $params['content'],
':title' => $params['title'],
':status' => $params['status'],
':rate' => $params['rate'],
':category' => $params['category'],
':created' => $cDate,
':changed' => $chang,
':target'=> 1
));
Unhandled Exception.
SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
You can find the error back in the log.
Time : 18:19:05
SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
Raw SQL : INSERT INTO post (user_id,post_name,color,start_date,expire_date,content,title,status,rate,category,created,changed,target) VALUES (:user_id,:post_name,:color,:start_date,:expire_date,:content,:title,:status,:rate,:category,:created,:changed,:target)
This is my vardump form $_POST form pass
array(9) {
["color"]=>
string(6) "c22bc2"
["start_date"]=>
string(19) "2014-12-31 18:23:31"
["expire_date"]=>
string(19) "2015-01-08 18:23:33"
["content"]=>
string(70) "
sDOROS)()GJ)*(EH)* VN#MT#:????><?<>?>??)T#\\\'\\
"
["title"]=>
string(23) "Tesssssssssssssssssssss"
["status"]=>
string(7) "publish"
["target"]=>
string(4) "stud"
["rate"]=>
string(1) "5"
["category"]=>
string(5) "w_zal"
}
If needed
$cDate = date("Y-m-d H:i:s");
$chang = 0;
public function post_name()
{
global $db;
$n = $db->row("SELECT max(id) as id FROM post");
$post_name = $this->user . "-" . $n['id'] . "-" . session_id();
return $post_name;
}
private function user_id()
{
global $db;
$userid = $db->row("SELECT * FROM users WHERE user_name = :name", array(
"name" => $_SESSION['user_name']
));
$this->user_id = $userid['user_id'];
return $this->user_id;
}
Whole class : http://pastebin.com/ehPazdMm
This database class internally adds the colons already. In the readme examples are given where they show that you have to not put a colon in the keys of the array you're going to bind.
You can see this in line 142 of the class as well, the function ->bind()
:
public function bind($para, $value)
{
$this->parameters[sizeof($this->parameters)] = ":" . $para . "\x7F" . utf8_encode($value);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.