douoyou3348 2014-07-16 15:41
浏览 37

PHP,MYSQL,PDO我试图通过管理页面更新用户帐户

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;
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等
    • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
    • ¥15 qt6.6.3 基于百度云的语音识别 不会改
    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
    • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
    • ¥20 测距传感器数据手册i2c