简体   繁体   中英

record inserts, but doesn't update mysql

I'm having an issue trying to update my database. I'm able to insert if it doesn't exist, but it doesn't update the record if exists. I think is not finding the current values of the table. Any ideas?

<?php
function add_log($input_output, $l_sales, $l_enroll, $l_offers)
{
    global $database;
    $date           =   date('m-d-Y');
    $l_sales        =   safety_filter($l_sales);
    $l_enroll       =   safety_filter($l_enroll);
    $l_offers       =   safety_filter($l_offers);
    $cusersup       =   get_the_current_user('u_manager');
    $cuseropm       =   get_the_current_user('u_opsmanager');
    $cuserid        =   get_the_current_user('id');
    $cuser          =   get_the_current_user('user_name');

    if($input_output == 'input')
    {
        $query_call = mysql_query("SELECT 1 FROM $database->log WHERE l_date='$date' AND l_user_name='$cuser'");
        if(mysql_num_rows($query_call) > 0)
        {
            while($list_calls = mysql_fetch_assoc($query_call))
            {
                $old_calls = $list_calls['l_calls'];
                $old_sales = $list_calls['l_sales'];
                $old_enroll = $list_calls['l_enroll'];
                $old_offers = $list_calls['l_offers'];
            }


            $update = mysql_query("UPDATE $database->log SET
            l_call=[$old_calls] + [1],
            l_sales=[$old_sales] + [$l_sales],
            l_enroll=[$old_enroll] + [$l_enroll],
            l_offers=[$old_offers] + [$l_offers]
            WHERE l_date='$date' AND l
            _user_name='$cuser'");
            if(mysql_affected_rows() > 0){return true;  }
            else { if($update == true){ return true; } else { return false; } }
        }
        else
        {

            mysql_query("INSERT INTO $database->log (l_date, l_user_name, l_calls, l_sales, l_enroll, l_offers) VALUES ('$date', '$cuser', '1', '$l_sales', '$l_enroll', '$l_offers')");
            if(mysql_affected_rows() > 0){return true; }
            else{ return false; }
        }   
    }
}
    ?>

I think the problem is that you are selecting 1 ("SELECT 1 FROM..."), so you are never getting any of the values from the table (just the number "1"). This tells you something is there, but doesn't actually return any values.

Try selecting all fields ("SELECT * FROM..."), or at least list the fields you need to do the update.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM