[Solved] You have an error in your SQL syntax…?


You will have to check if there is no starting and trailing comma’s in the $columns or $values variables.
Plus, just to be sure, put appropriate quotes around the columns and values individually.

public function insert($data, $table) { 
$columns = ""; 
$values = ""; 

foreach ($data as $column=>$value) 
{
     $columns .= "`" . $column . "`, ";
     $values .=  "'" . $value . "', ";
 }

 $columns = substr($columns, 0, strlen($columns)-2);
 $values = substr($values, 0, strlen($values)-2);
 $sql = "insert into ".$table." (".$columns.") values (".$values.")"; mysql_query($sql) or die (mysql_error()); return mysql_insert_id(); }

0

solved You have an error in your SQL syntax…?