The code----
public function create(){
global $database;
//this code works perfectly to insert the new user into my database.
$sql = "INSERT INTO users (";
$sql .= "username, password, first_name, last_name";
$sql .= ") VALUES ('";
$sql .= $database->escape_value($this->username) ."', '";
$sql .= $database->escape_value($this->password) ."', '";
$sql .= $database->escape_value($this->first_name) ."', '";
$sql .= $database->escape_value($this->last_name) ."')";
if($database->query($sql)){
$this->id = $database->insert_id();
return true;
}else{
return false;
}
public function create()
{
global $database;
//this code is to be universal for other database types but it is not working.
$attributes = $this->attributes();
$sql = "INSERT INTO ".self::$table_name." (";
$sql .= join(", ", array_keys($attributes));
$sql .= ") VALUES ('";
$sql .= join("', '", array_values($attributes));
$sql .= "')";
if ($database->query($sql)) {
$this->id = $database->insert_id();
return true;
} else {
return false;
}
}
the problem - suppose to be generalizing the script so it can be used in any database structure. Its not working in my wamp.
$attributes. That way, how can we know what the heck you're trying to do with the db?