dqs13465424392 2015-05-08 17:10
浏览 157

无法更新mysql列中的值

I'm not sure what's happening. I'm trying to update a 'users' table with a value of 0 using a function that suspends a user. The column name is 'active', tinyint(1) with a default value of 0, and I've tried the query with 'active = 0', 'active = false', active = !active', 'active = NOT active', active = 'DEFAULT', none of these queries are returning an error, but none of them are updating the table... I've also tried binding the value in numerous ways to no avail...

function suspendUser($id){

        global $dbc;

        $sus = $dbc->prepare("UPDATE users SET active = 0 WHERE user_id = :id");
        $sus->bindParam(':id', $id, PDO::PARAM_INT);
        $sus->execute();

        if($sus->rowCount() > 0){
            return true;
            }
        else{
            return 'There was an error with your request.';
            }
        }

this is in my config file

try { 
$dbc = new PDO("mysql:host=$db_host;dbname=$db_name;charset=utf8",  $db_username, $db_password);
$dbc->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); }
 catch(PDOException $e){ 
echo "Connection failed: " . $e->getMessage(); }

// create the error handler
    function my_error_handler($e_number, $e_message, $e_file, $e_line, $e_vars){
        global $debug, $contact_email;

        $message = "An error occurred in script '$e_file' on line $e_line:     $e_message";
        $message .= print_r($e_vars, 1);

    if($debug){
        echo '<div class="error">'.$message.'</div>';
        debug_print_backtrace();
        }
    else{
        error_log($message, 1, $contact_email);

        if(($e_number != 'E_NOTICE') && ($e_number < 2048)){
            echo '<div class="error">A system error occurred. We apologize for the inconvenience.</div>';
            }
        } 
    }

    set_error_handler('my_error_handler');

this is the javascript function

function suspendUser(uid){
        $.ajax({ url: 'lib/user-edit.php',
                data:{action: 'suspend', id: uid},
                type:'post',
                success: function(t){
                    $('#' + uid).prepend('<p>'+t+'<br>Sucessfully suspended</p>');
                    }
                });
        }

and then

if(isset($_POST['action'])){
        $action = $_POST['action'];
        }
    if(isset($_POST['id'])){
        $id = $_POST['id'];
        }
    if(isset($_POST['role'])){
        $role = $_POST['role'];
        }
    else{
        return 'There was an error with your request.';
        }

// define the function to execute based on the posted action

if($action == 'change'){
    changeRole($id);
    }
if($action == 'delete'){
    deleteUser($id);
    }
if($action == 'suspend'){
    suspendUser($id);
    }

I've added this to the function:

function suspendUser($id){

    global $dbc;

    $sus = $dbc->prepare("UPDATE users SET active = 0 WHERE user_id = :id");
    $sus->bindParam(':id', $id, PDO::PARAM_INT);
    $sus->execute();

     if (!$dbc->execute()) {
        $err = print_r($dbc->errorInfo());
        return $err;
         }

    if($sus->rowCount() > 0){
        $err = print_r($dbc->errorInfo());
        return $err;
        }
    else{
        $err = print_r($dbc->errorInfo());
        return $err;
        }
    }

I'm still not getting errors.

  • 写回答

2条回答 默认 最新

  • duadpnld426905 2015-05-08 17:16
    关注

    If you are updating from zero to zero, the row count will be zero - because none of the rows changed.

    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值