Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在开关中使用声明的变量_Php_Jquery_Ajax_Switch Statement_Case - Fatal编程技术网

Php 在开关中使用声明的变量

Php 在开关中使用声明的变量,php,jquery,ajax,switch-statement,case,Php,Jquery,Ajax,Switch Statement,Case,我正在使用开关来提交、删除或取消。我不知道我是否做错了什么,但我无法访问提交的任何输入的值。我可以在交换机外面回音,它们工作得很好 以下是Ajax: function check_url(recieve_url, type) { if (recieve_url == undefined || recieve_url == null) { alert("recieve_url is not set!"); } $.ajax({ url : r

我正在使用开关来提交、删除或取消。我不知道我是否做错了什么,但我无法访问提交的任何输入的值。我可以在交换机外面回音,它们工作得很好

以下是Ajax:

function check_url(recieve_url, type) {
    if (recieve_url == undefined || recieve_url == null) {
        alert("recieve_url is not set!");
    }
    $.ajax({
        url : recieve_url,
        type : 'POST',
        dataType : 'json',
        data : "type="+type,
        success : function (result) {
            //alert(result['bg'] + result['message'] + result['caption'])

            myApp.alert(result['message'], result['title'], function () {
                if (result['redirect'] != null || result['redirect'] != undefined){
                    window.location = "<?php echo $this->url;?>"+result['redirect'];
                }
            });
                //myApp.alert(result['message'], result['title']);


        },
        error : function (xhr, ajaxOptions, thrownError) {
            myApp.alert(xhr.responseText);
            myApp.alert(xhr.status);
            myApp.alert(thrownError);
        }
    })

}

我可以在切换之前
回显
它们。所以我不明白为什么我不能在开关中使用它们。

那么PHP中的$type var实际上得到了一个值?也为交换机添加默认大小写,以捕获意外值删除或注释“echo$address”。$admin\u check;'对于ajaxrequest@miglio,这不会解决任何问题,我可以在访问Ajax URL时回显它。它不允许在案例中使用变量。
function EditSubmit($ID = ''){
    //get the case name to direct to
    $type = htmlspecialchars(trim($_POST["type"]));
    $sql = "SELECT * FROM staff WHERE id = :id";
    $arr  = array(":id" => $ID);
    $result = $this->database->DBQry($sql, $arr);
    $id = $result[0]['id'];
    $email = $result[0]['email'];
    $admin = $result[0]['admin'];
    $staff = $result[0]['staff'];
    $disabled = $result[0]['disabled'];
    $active = $result[0]['active'];
    $admin_check = isset($_POST['admin_check']);
    $address = isset($_POST['address']) ? $_POST['address'] : '';
    echo $address.' '.$admin_check;

    switch ($type) {
        case 'submit':
        if ($admin == 1){
            $response = array(
                'message' => 'Cannot edit an administrator',
                'title' => 'Error'
                );
        }else{
            $arr = array(":address" => $address, ":admin" => $admin_check, ":staff" => 1, ":disabled" => 1, ":active" => 1);
            $this->database->DBSet($arr,'staff',$whr = 'WHERE id = '.$ID);
            $response = array(
                'message' => 'active'.$address.' admin'.$_SESSION['qun'].' staff'.$staff_box.' disabled'.$disabled_box,
                'title' => 'Success',
                'redirect' => 'Staff/Edit'
                );
        }
        break;
        case 'delete':
        if ($admin == 1){
            $response = array(
                'message' => 'Cannot delete an administrator',
                'title' => 'Error'
                );
        }else{
            $this->database->DBDel('staff',$whr = 'WHERE ID = '.$ID);
            $response = array(
                'message' => 'Staff member deleted',
                'title' => 'Success',
                'redirect' => 'Staff/Edit'
                );
        }
        break;
        case 'cancel':
        $response = array(
            'message' => 'Nothing has been changed',
            'title' => 'Canceled',
            'redirect' => 'Staff/Edit'
            );
        break;
    }


    echo json_encode($response);

}