public function insert($table, $data = array()) {
$fieldnames = array_keys ( $data );
var_dump(implode ( ' ,', $fieldnames ));
$name = '( ' . implode ( ' ,', $fieldnames ) . ' )';
$value = '(:' . implode ( ', :', $fieldnames ) . ' )';
$query = "INSERT INTO $table";
$query .= $name . ' VALUES ' . $value;
var_dump($query);
$insert = $this->start->prepare ( $query );
return $insert->execute ( $data );
}
Question: ok i have a function that helps me simplify the insert statement (pdo) the problem is is when i insert a field if “group” name on it
$a['group'] = $_POST['group'];
$a['tag'] = $_POST['tag'];
$a['information'] = $_POST['information'];
$status= $this->insert ( 'groups', $a);
it will generate a mysql error like
PDOStatement::execute()
[pdostatement.execute]:
SQLSTATE[42000]: Syntax error or
access violation: 1064 You have an
error in your SQL syntax; check the
manual that corresponds to your MySQL
server version for the right syntax to
use near ‘group ,tag ,information )
VALUES (‘agroup’, ‘atag’,
‘ainformation’ )’
this is the query
INSERT INTO groups( group ,tag ,information ) VALUES (:group, :tag, :information )
im guessing that it should be
INSERT INTO groups( "group" ,"tag" ,"information" ) VALUES (:group, :tag, :information )
im not sure where should we start from.
Thanks for looking in
Adam Ramadhan
Where you have:
You need to have:
Do this with the following: