I am trying to update a user account via an admin page with PDO. I can update it manually with the following
$userInsert = DB::getInstance()->update('quotes', 245, array('firstname' => 'Helen'));
But i want to do it via the $_GET method. Here is what i think is correct
<?php
if(Input::exists()) {
if(Token::check(Input::get('token'))) {
$userInsert = DB::getInstance()->update('quotes', Input::get('id'), array(
'firstname', '=', escape(Input::get('firstname')),
'lastname', '=', escape(Input::get('lastname')),
'email', '=', escape(Input::get('email')),
'alt_email', '=', escape(Input::get('alt_email')),
'phone', '=', escape(Input::get('phone')),
'mobile', '=', escape(Input::get('mobile')),
'company_name', '=', escape(Input::get('company_name')),
'ticker', '=', escape(Input::get('ticker')),
'shares_held', '=', escape(Input::get('shares_held')),
'shares_sell', '=', escape(Input::get('shares_sell')),
'comments', '=', escape(Input::get('comments'))
));
Session::flash('success', '<pre class="pre-success">Client Account Updated Successfully</pre>');
Redirect::to('admin.php');
}
}
Here is a copy of my Input class
<?php
class Input {
public static function exists($type = 'post') {
switch($type) {
case 'post':
return (!empty($_POST)) ? true : false;
break;
case 'get':
return (!empty($_GET)) ? true: false;
break;
default:
return false;
break;
}
}
public static function get($item) {
if(isset($_POST[$item])) {
return $_POST[$item];
} else if (isset($_GET[$item])) {
return $_GET[$item];
}
return '';
}
}
I just can't seem to get it to update the database, i don't get any errors and it redirects with the success message.
************EDIT*******************
Sorry about that, Update function now included
public function update($table, $id, $fields = array()) {
$set = '';
$x = 1;
foreach($fields as $name => $value) {
$set .= "{$name} = ?";
if($x < count($fields)) {
$set .= ', ';
}
$x++;
}
$sql = "UPDATE {$table} SET {$set} WHERE id = {$id}";
if(!$this->query($sql, $fields)->error()) {
return true;
}
return false;
}