Hi there, Guys, I really need your help! I'm seriously stuck in my project...
Help with PHP OOP PDO
3
Hi there,
Guys, I really need your help! I'm seriously stuck in my project...
I learn the OOP in PHP, now I build a LOGIN & RESITER system but, when I try insert new user into the DB I get an error:
I have 2 files with 2 classes, the first its User class:
and the second its Database class with Insert Method:
The $arr variable give me array with user info:
If I fill manually all information into the query, everything is work! But if I use the variable with array, its isn't work
I tried anything that I know, I have no idea what to do.... I'm really frustrated...
Can anyone help me please? I will very that you 4 all your help!
Guys, I really need your help! I'm seriously stuck in my project...
I learn the OOP in PHP, now I build a LOGIN & RESITER system but, when I try insert new user into the DB I get an error:
Code:
Fatal error: Uncaught exception 'Exception' with message '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) VALUES ('NewUserName', '68f7ad648943bf04ec61ae61cf8b3e934549eb9de8220cb18' at line 1' in C:\xampp\htdocs\login\register.php:54 Stack trace: #0 {main} thrown in C:\xampp\htdocs\login\register.php on line 54 PHP Code:
class Users {
private $db;
public function __construct(){
$this->db = new Database();
}
public function create($fields = []){
$arr = array_values($fields);
if (!$this->db->insertRow("INSERT INTO users (username, password, salt, fullname, joined, group) VALUES (?, ?, ?, ?, ?, ?)", $arr)) {
throw new Exception('There was a problem creating an account!');
}
}
}
PHP Code:
public function insertRow($query, $params){
try {
$stmt = $this->datab->prepare($query);
$stmt->execute($params);
return TRUE;
} catch (Exception $e){
throw new Exception($e->getMessage());
}
}
Code:
Array
(
[0] => NewUserName
[1] => 0178890e573c0aeb6875def9231230defaf021f2e1747ae40d8d384a9d1eb0d2
[2] => ùë....OÉesæ":Æ'·\áè!Èû0ISIõòá1
[3] => UserFullName
[4] => 2015-07-05 21:15:39
[5] => 1
) I tried anything that I know, I have no idea what to do.... I'm really frustrated...
Can anyone help me please? I will very that you 4 all your help!
- chickahoona
- [1] reply
- exma
Next Topics on Trending Feed
-
3