使用jquery / ajax插入数据到数据库,我没有得到蚂蚁错误,但没有插入数据库的值 [英] Inserting data in to database using jquery/ajax,i am not getting ant error but values not inserting in to the database

查看:98
本文介绍了使用jquery / ajax插入数据到数据库,我没有得到蚂蚁错误,但没有插入数据库的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用jquery / ajax插入数据到数据库中,我没有得到蚂蚁错误,但没有使用codeigniter插入到数据库中,我做的任何错误都意味着请给我建议

 < script type =text / javascript> 
$(document).ready(function(){
$(#personal-info)。click(function(){
e.preventDefault();
var消息= $(#message)。val();
// var password = $(#password)。val();


$ .ajax ({
type:POST,
url:<?php echo base_url();?> index.php / Profile_cntrl / buyer_communication,
data:{message:message },
成功:函数(数据)
{
alert('成功插入');
},
错误:function()
{
alert('fail');
}
});
});
});
< / script>

表格

 < form class =form-horizo​​ntalmethod =POSTid =personal-inforole =formaction =#> 
< div class =panel-footer>
< div class =input-group>

< input type =hiddenname =suppidid =suppidvalue =<?php echo $ row-> supplier_id;?> class =form-control/>
< input type =hiddenname =proidid =proidvalue =<?php echo $ row-> product_id;?> class =form-control/>
< input type =hiddenname =custidid =custidvalue =<?php echo $ row-> Customer_id;?> class =form-control/>


$ b < span class =input-group-btn>
< button class =btn btn-primary btn-smid =submit-pname =submit-p>发送< / button>
<! - < input type =submitname =submit-pid =submit-pvalue =sendclass =btn btn-primary btn-sm> - - >
< / span>
< / div>
< / div>
< / form>

控制器
< pre $ lt; code> public function buyer_communication(){

$ supp_id = $ this-> input-> post('suppid');
$ product_id = $ this-> input-> post('proid');
$ cust_id = $ this-> input-> post('custid');



$ result1 = $ this-> Profile_model-> fetch_Data($ product_id);


$ Userid = $ this-> session-> userdata('id');
$ result3 = $ this-> session-> userdata('tt');
data4 = array(
'message'=> $ this-> input-> post('message'),
'supplier_id'=> $ supp_id,
'product_id'=> $ product_id,
'Customer_id'=> $ cust_id,
'From'=> $ result3,
);

$ this-> Profile_model-> buyer_insert($ data4);

重定向('welcome / buyermessageview?id ='。$ product_id);
}

模型

 函数buyer_insert($ data4){
$ this-> db-> insert('communication',$ data4);
return($ this-> db-> affected_rows()!= 1)?假:真;


解决方案

/ strong>

 < script> 
$(document).ready(function(){
$(#personal-info)。submit(function(e){
e.preventDefault();

$ b var suppid = $(#suppid)。val();
var proid = $(#proid)。val();
var custid = $ (#custid).val();
var message = $(#message).val();

$ .ajax({
type: POST,
url:<?php echo base_url();?> index.php / Profile_cntrl / buyer_communication,
data:{suppid:suppid,proid:proid,custid:custid,消息:消息},
成功:函数(数据)
{
alert('SUCCESS !!');
},
错误:function()
{
alert('fail');
}
});
});
});
< / script>

控制器
公共职能buyer_communication(){

  $ result1 = $ this-> Profile_model-> fetch_Data($ product_id); 


$ Userid = $ this-> session-> userdata('id');
$ result3 = $ this-> session-> userdata('tt');
$ data4 = array(
'message'=> $ this-> input-> post('message'),
'supplier_id'=> $ this-> ('suppid'),
'product_id'=> $ this-> input-> post('proid'),
'Customer_id'=> $ this- >输入 - >后('custid'),
'From'=> $ result3,
);

$ this-> Profile_model-> buyer_insert($ data4);

重定向('welcome / buyermessageview?id ='。$ product_id);
}


Inserting data in to database using jquery/ajax,i am not getting ant error but values not inserting in to the database using codeigniter,any mistake i done means please suggest me

<script type="text/javascript">
        $(document).ready(function () {
            $("#personal-info").click(function () {
                e.preventDefault();
                var message = $("#message").val();
                //  var password= $("#password").val();


                $.ajax({
                    type: "POST",
                    url: "<?php echo base_url(); ?>index.php/Profile_cntrl/buyer_communication",
                    data: {message: message},
                    success: function (data)
                    {
                        alert('Successfully inserted');
                    },
                    error: function ()
                    {
                        alert('fail');
                    }
                });
            });
        });
    </script>

form

<form class="form-horizontal" method="POST" id="personal-info"  role="form" action="#"> 
                            <div class="panel-footer">
                                <div class="input-group">

                                    <input type ="hidden" name="suppid" id="suppid" value="<?php echo $row->supplier_id; ?>" class="form-control" />
                                    <input type ="hidden" name="proid" id="proid" value="<?php echo $row->product_id; ?>" class="form-control" />
                                    <input type ="hidden" name="custid" id="custid" value="<?php echo $row->Customer_id; ?>" class="form-control" />



                                    <input id="messagee" name="message" type="text" class="form-control input-sm chat_input" placeholder="Write your message here..." />
                                    <span class="input-group-btn">
                                        <button class="btn btn-primary btn-sm" id="submit-p" name="submit-p">Send</button>
                                        <!--<input type="submit" name="submit-p" id="submit-p" value="send" class="btn btn-primary btn-sm" >-->
                                    </span>
                                </div>
                            </div>
                        </form>

controller

public function buyer_communication() {

    $supp_id = $this->input->post('suppid');
    $product_id = $this->input->post('proid');
    $cust_id = $this->input->post('custid');



    $result1 = $this->Profile_model->fetch_Data($product_id);


    $Userid = $this->session->userdata('id');
    $result3 = $this->session->userdata('tt');
    $data4 = array(
        'message' => $this->input->post('message'),
        'supplier_id' => $supp_id,
        'product_id' => $product_id,
        'Customer_id' => $cust_id,
        'From' => $result3,
    );

    $this->Profile_model->buyer_insert($data4);

    redirect('welcome/buyermessageview?id=' . $product_id);
}

Model

function buyer_insert($data4) {
        $this->db->insert('communication', $data4);
        return ($this->db->affected_rows() != 1) ? false : true;
    }

解决方案

modified script

<script>
        $(document).ready(function(){
            $("#personal-info").submit(function(e){
               e.preventDefault();


               var suppid = $("#suppid").val();
               var proid = $("#proid").val();
               var custid = $("#custid").val();
                var message = $("#message").val();

                $.ajax({
                    type: "POST",
                    url: "<?php echo base_url(); ?>index.php/Profile_cntrl/buyer_communication",
                    data: {suppid:suppid,proid:proid,custid:custid,message:message},
                    success:function(data)
                    {
                        alert('SUCCESS!!');
                    },
                    error:function()
                    {
                        alert('fail');
                    }
                });
            });
        });
    </script>

controller public function buyer_communication() {

    $result1 = $this->Profile_model->fetch_Data($product_id);


    $Userid = $this->session->userdata('id');
    $result3 = $this->session->userdata('tt');
    $data4 = array(
        'message' => $this->input->post('message'),
        'supplier_id' => $this->input->post('suppid'),
        'product_id' => $this->input->post('proid'),
        'Customer_id' => $this->input->post('custid'),
        'From' => $result3,
    );

    $this->Profile_model->buyer_insert($data4);

    redirect('welcome/buyermessageview?id=' . $product_id);
}

这篇关于使用jquery / ajax插入数据到数据库,我没有得到蚂蚁错误,但没有插入数据库的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆