试图从PHP脚本更新记录

时间:2011-12-12 18:14:47

标签: php mysql

如果选中checkboxinput_c复选框,我试图从php脚本更新记录。我无法从脚本中获取更新记录。但是,如果我在mysql控制台中键入下面的确切命令,则记录会正确更新。

                if($bean->pendinginput_c == 'on')
            {
            $sql = "UPDATE cases SET status='Pending Input' WHERE id='958ca4e5-51'";
            }   

在脚本中,您将看到还有其他正在运行的sql语句。没有更新,只需选择。

$sql_nmb = "SELECT case_number FROM cases where id='".$bean->parent_id."'";
            $result = $bean->db->query($sql_nmb, true);
            $case = $bean->db->fetchByAssoc($result);               

            $sql = 'SELECT c.assigned_user_id , c.id , cc.contact_id as contact_id, co.first_name , co.last_name , ear.email_address_id ,ea.email_address FROM cases as c 
                        LEFT JOIN contacts_cases as cc on c.id = cc.case_id
                        LEFT JOIN contacts as co on co.id = contact_id
                        LEFT JOIN email_addr_bean_rel ear ON ear.bean_id = contact_id
                        LEFT JOIN email_addresses as ea on ea.id = ear.email_address_id
                        WHERE c.id = "'.$bean->parent_id.'" and cc.deleted = 0 and ear.deleted = 0 and ea.deleted = 0';
            $resp = $bean->db->query($sql, true); 

2 个答案:

答案 0 :(得分:0)

您是否曾尝试在查询中转义',如下所示:\'

编辑:假设您实际上是在使用mysql_query($sql) ...或其他一些查询函数进行查询。

答案 1 :(得分:0)

试试这个:

if($bean->pendinginput_c == 'on'){
    $sql = "UPDATE cases SET status='Pending Input' WHERE id='958ca4e5-51'";
    $bean->db->query($sql, true); 
}

另外检查$ bean-> pendinginput_c是否真的等于“on”。在if语句上方回显它以进行双重检查。

祝你好运!