weixin_33721427 2016-02-29 10:55 采纳率: 0%
浏览 32

AJAX数组到PHP不起作用

I have a set of checkboxes. If you click them, bits of a SQL string should be send to a php file, when a button is clicked.

The checkbox setup looks as follows:

<input type="checkbox" class="checkboxes" name="checkb[]" value="SYSTEM LIKE '%system%'">

The ajax looks as follows:

$("#button1").click(function(e) {
    var category_id = {};
    category_id['checkboxvalue'] = $('.checkboxes:checked').serialize();
    $.ajax({
        type: "POST",
        url: "allgemein.php",
        data: category_id,
        success: function(response) {
            $("#resulttable").show().html(response);
        }
    });
});

In php i try to call them like this:

$strWhere = '1=1';

if(true === isset($_POST['checkb']) && 0 < sizeof($_POST['checkb']))
{
    $strWhere .= '(';
    foreach($_POST['checkb'] as $checkboxval)
    {
        $strWhere .= '"'.$checkboxval.'" OR ';
    }
    //remove last OR
    $strWhere = substring($strWhere, 0, -3);
    $strWhere .= ')';
}

$strWhere gets added to the WHERE clause of my SQL query.

Can someone say why this is not working? $strWhere is always 1=1, it never enters the if-loop... somehow I'm not calling the array correctly with $_POST['checkb'] and I just can't figure out why.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 宇视监控服务器无法登录
    • ¥15 PADS Logic 原理图
    • ¥15 PADS Logic 图标
    • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
    • ¥20 气象站点数据求取中~
    • ¥15 如何获取APP内弹出的网址链接
    • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
    • ¥50 STM32单片机传感器读取错误
    • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
    • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)