Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.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中更新现有sql数据_Php_Ajax_Post_Cakephp - Fatal编程技术网

在PHP中更新现有sql数据

在PHP中更新现有sql数据,php,ajax,post,cakephp,Php,Ajax,Post,Cakephp,目前正在尝试找出如何在php中更新现有SQL数据。我的输入字段会自动填充预先存在的数据,但每当我点击“保存”更改现有数据时,它都不会执行任何操作。没有错误或警告消息 这是我的控制器: public function settings() { $user = $this->UserAuth->getUser(); $userid = $this->UserAuth->getUserId(); //$userEntity = $this->

目前正在尝试找出如何在php中更新现有SQL数据。我的输入字段会自动填充预先存在的数据,但每当我点击“保存”更改现有数据时,它都不会执行任何操作。没有错误或警告消息

这是我的控制器:

 public function settings()
{
    $user = $this->UserAuth->getUser();
    $userid = $this->UserAuth->getUserId();


    //$userEntity = $this->Push->find()->where(['user_id = ' => $userid])->order('time')->toArray($this->request->data, ['validate'=>false]);
    //$query = $this->Push->find('all', ['conditions' => ['Push.user_id' => $userid]])->last();

    $userEntity =  $this->Push->find('all', ['conditions' => ['Push.user_id' => $userid]])->last();


    if($this->request->is('patch', 'post', 'put')) {
        $errors = $userEntity->errors();
        if($this->request->is('ajax')) {
            if(empty($errors)) {
                $response = ['error'=>0, 'message'=>'success'];
            } else {
                $response = ['error'=>1, 'message'=>'failure'];
                $response['data']['push'] = $errors;
            }
            echo json_encode($response);exit;
        } else {
            if(empty($errors)) {
                        if(!empty($this->request->data($userEntity['iosapikey']))) {
                            $userEntity['iosapikey'] = $this->request->data['Push']['iosapikey'];
                        }
                        if(!empty($this->request->data['Push']['androidapikey'])) {
                            $userEntity['androidapikey'] = $this->request->data['Push']['androidapikey'];
                        }
                        if(!empty($this->request->data['Push']['restapikey'])) {
                            $userEntity['restapikey'] = $this->request->data['Push']['restapikey'];
                        }
                        if(!empty($this->request->data['Push']['segments'])) {
                            $userEntity['iosapikey'] = $this->request->data['Push']['segments'];
                        }
                        if(!empty($this->request->data['Push']['tags'])) {
                            $userEntity['androidapikey'] = $this->request->data['Push']['tags'];
                        }
                        if(!empty($this->request->data['Push']['deeplinks'])) {
                            $userEntity['restapikey'] = $this->request->data['Push']['deeplinks'];
                        }

                        if($this->Push->save($userEntity, ['validate'=>false])) {
                            $this->Flash->success(__('Push settings have been updated successfully'));
                            //$this->redirect(['action'=>'index', 'page'=>$page]);
                        } else {
                            $this->Flash->error(__('Unable to update push settings, please try again'));
                        }
                    }
                }
    } else {
                if(!empty($userEntity['iosapikey'])) {
                    $userEntity['iosapikey'] = $userEntity['iosapikey'];
                }
                if(!empty($userEntity['androidapikey'])) {
                    $userEntity['androidapikey'] = $userEntity['androidapikey'];
                }
                if(!empty($userEntity['restapikey'])) {
                    $userEntity['restapikey'] = $userEntity['restapikey'];
                }
                if(!empty($userEntity['segments'])) {
                    $userEntity['segments'] = $userEntity['segments'];
                }
                if(!empty($userEntity['tags'])) {
                    $userEntity['tags'] = $userEntity['tags'];
                }
                if(!empty($userEntity['deeplinks'])) {
                    $userEntity['deeplinks'] = $userEntity['deeplinks'];
                }
    }


    $this->set(compact('userEntity'));
    $this->set('_serialize', ['push']);


        } 
这是我的模板:

<div class="panel-body">
      <?php echo $this->element('Usermgmt.ajax_validation', ['formId'=>'editPushForm', 'submitButtonId'=>'editPushSubmitBtn']); ?>
      <?php echo $this->Form->create($userEntity, ['id'=>'editPushForm', 'class'=>'form-horizontal', 'type'=>'text']);?>
                <div class="form-group col-md-9 col-sm-10">
                    <label>iOS API Key:</label>
                    <div class="">
                        <?php echo $this->Form->input('Push.iosapikey',['type'=>'text', 'label'=>false, 'div'=>false, 'class'=>'form-control']);?>
                    </div>
                </div>
                <div class="form-group col-md-9 col-sm-10">
                    <label>Android API Key:</label>
                    <div class="">
                        <?php echo $this->Form->input('Push.androidapikey',['type'=>'text', 'label'=>false, 'div'=>false, 'class'=>'form-control']);?>
                    </div>
                </div>
                <div class="form-group col-md-9 col-sm-10">
                    <label>REST API Key:</label>
                    <div class="">
                        <?php echo $this->Form->input('Push.restapikey',['type'=>'text', 'label'=>false, 'div'=>false, 'class'=>'form-control']);?>
                    </div>
                </div>
                <div class="form-group col-md-9 col-sm-10">
                    <label>Segments:</label>
                    <div class="">
                        <?php echo $this->Form->input('Push.segments',['type'=>'text', 'label'=>false, 'div'=>false, 'class'=>'form-control']);?>
                    </div>
                </div>
                <div class="form-group col-md-9 col-sm-10">
                    <label>Tags:</label>
                    <div class="">
                        <?php echo $this->Form->input('Push.tags',['type'=>'text', 'label'=>false, 'div'=>false, 'class'=>'form-control']);?>
                    </div>
                </div>
                <div class="form-group col-md-9 col-sm-10">
                    <label>Deeplinks:</label>
                    <div class="">
                        <?php echo $this->Form->input('Push.deeplinks',['type'=>'text', 'label'=>false, 'div'=>false, 'class'=>'form-control']);?>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-offset-3 col-sm-offset-2 col-sm-3">
                        <?php echo $this->Form->Submit(__('Save'), ['div'=>false, 'class'=>'btn btn-primary pushbutton', 'id'=>'editPushSubmitBtn']); ?>
                    </div>
                </div>
                <?php echo $this->Form->end();?>

iOS API密钥:
Android API密钥:
REST API密钥:
部分:
标签:
深度链接:


我确信我在某个地方还没有发现一个小错误,但是我花了很多时间在这个问题上,没有任何积极的结果,我认为是时候寻求一些帮助了。

Cake PHP find函数返回一个对象,所以我会请求您使用类似$userEntity->iosapikey=$this->request->data['Push']['iosapikey']的语句;要分配值并在cakephp中启用调试,您需要从数据库中读取一个实体,然后检查它是否有错误?在那个时候它永远不会有。错误来自设置(例如,使用
patchEntity
)无效数据。另外,您的所有行,如
$userEntity['iosapikey']=$userEntity['iosapikey']]
都是毫无意义的。如果相应的输入字段为空,您似乎不想更新设置,对吗?