i have created a query class to handle all my basic sql functions, inside the class i have a basic function that inserts data using prepared statements that is the 'Insert' function, am not quite sure why but i keep getting the same error(listed above) every time i call the function
class Query
{
private $conn;
private $table;
public function __construct($conn, $table)
{
$this->conn = $conn;
$this->table = $table;
}
public function Insert($fields, $placeholders, $binders, $values)
{
$field_val= implode(', ', $fields);
$ph=implode(', ', $placeholders);
array_walk($values, function(&$x) {$x = "'$x'";});
$val = implode(', ', $values);
$query = 'INSERT INTO '.$this->table.' ('.$field_val.') VALUES('.$ph.')';
$stmt = $this->conn->prepare($query);
$stmt->bind_param(''.$binders.'', $val);
$stmt->execute();
}
}
this is an example of the function in use to insert data into a comments table, the connection comes form a separate database file included in the module
$database = new Database();
$conn = $database->connect();
//values
$comment_date = mysqli_real_escape_string($conn, htmlspecialchars($_POST['date-comment']));
$commenter = mysqli_real_escape_string($conn, htmlspecialchars($_POST['comment_name_of']));
$comment = mysqli_real_escape_string($conn, htmlspecialchars($_POST['comment']));
$comments_save = new Query($conn, 'nw_comments');
$fields = array('commenter_name', 'comment_value', 'date_commented');
$placeholders = array('?', '?', '?');
$binders = "sss";
$values = array($commenter, $comment, $comment_date);
$comments_save->Insert($fields,$placeholders,$binders,$values);