简体   繁体   English

Codeigniter-将输入值保存在mysql中

[英]Codeigniter - Save input value in mysql

I have an input in my code that update a value in MySQL, but is not working, if i set the value manually in PHPMyAdmin, the value display in HTML, but when i try update, return to 0. 我的代码中有一个输入会更新MySQL中的值,但不起作用,如果我在PHPMyAdmin中手动设置了该值,则该值以HTML显示,但是当我尝试更新时,返回0。

I have the same code to do a similar function, and have copied, and it still isn't working. 我有相同的代码来执行类似的功能,并且已经复制,但仍然无法正常工作。

Controller: 控制器:

function ordemmobile(){
    $ordemmobile = $this->input->post('ordemmobile');
    $id    = $this->input->post('id');

    if($id > 0){
        $data['ordemmobile'] = $ordemmobile;
        $data['id']    = $id;

        if( $this->categorias_model->alterar($data)){
            $ret = "success";
            $msg = "Ordem alterada com sucesso!";
        }else{
            $ret = "danger";
            $msg = "Erro ao alterar a ordem :(";
        }
    }else{
        $ret = "danger";
        $msg = "Erro ao alterar a ordem :(";
    }

    echo json_encode(array('status' => $ret , 'msg' => $msg));
}

View: 视图:

echo "<td><input type=\"number\" name=\"ordemmobile\" value=\"".$registro->ordemmobile."\" style=\"width:80px; margin:0\" class=\"ordemmobile\"  data-id=\"".$registro->id."\" data-url=\"".base_url('adm/'.$this->router->fetch_class().'/ordemmobile')."\" /><span style=\"display:none\">".$registro->ordemmobile."</span></td>";

Model (alterar): 型号(另类):

function alterar($data){
    $this->db->where('id',$data['id']);
    return $this->db->update('ga845_categorias',$data);
}

Looks like it should work if the inputs are getting posted. 如果输入已投入,看起来应该可以使用。 Checking both inputs would be a good idea. 检查两个输入都是一个好主意。

Consider this 考虑一下

function ordemmobile()
{
    $ordemmobile = $this->input->post('ordemmobile');
    $id = $this->input->post('id');

    if(empty($id) || empty($ordemmobile))
    {
        $ret = "danger";
        $msg = "Erro ao alterar a ordem :(";
    }
    else
    {
        $data['ordemmobile'] = $ordemmobile;
        $data['id'] = $id;

        if($this->categorias_model->alterar($data))
        {
            $ret = "success";
            $msg = "Ordem alterada com sucesso!";
        }
        else
        {
            $ret = "danger";
            $msg = "Erro ao alterar a ordem :(";
        }
    }

    echo json_encode(array('status' => $ret, 'msg' => $msg));
}

You should also take a good look at what your browser's Web Developer Tools tell you about the request to and response from the server. 您还应该仔细查看浏览器的Web开发人员工具告诉您的有关服务器请求和响应的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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