weixin_33670786 2016-04-15 02:35 采纳率: 0%
浏览 25

发送Ajax值到MySQL

i have 2 tables : 'excel'enter image description here and 'request' enter image description here

I get the value from input text and now i want to send the '9000' value into 'tarif' field in 'excel' table.

enter image description here

this is my controller :

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Ajax extends CI_Controller {

    function edit($excel_id, $tarif)
    {
        echo $excel_id;
        $this->load->model('request');
        $this->request->updatedata($tarif,$excel_id);

    }
}

my model:

<?php
class Request extends CI_Model {

    function updatedata($id,$tarif) 
   {
        $this->db->set('tariff', $tarif);
        $this->db->where('excel_id',$id);
        $query = $this->db->update('excel');
        return $query->result_array();
   }
}

this is my ajax, inside the view:

!DOCTYPE html>
<html>
<head>
    <title>Admin Kirim Undangan</title>
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

</head>
<body>

<h3>Customer Request</h3>

<?php
    foreach ($results as $value) {
?>

<table class="table">
    <tr>
        <td><?= $value['nama']?></td>
        <td><?= $value['phone']; ?></td>
        <td><?= $value['alamat_pengirim']?></td>
    </tr>
</table>

    <table class="table">
        <th>
            Alamat
        </th>
        <th>
            Tarif
        </th>

<?php        
     foreach ($undg[$value['req']] as $row) {        
?>
        <tr>
        <td><?php echo $row['alamat_tujuan']?></td>
        <td><input type="text" id="<?php echo $row['excel_id']?>" name="tarif"></input> <!-- id input text nya harus dibedakan berdasarkan excel_id -->
        <?php form_open(); ?>
        <button type="button" class="btn btn-primary btn-sm" onclick=update(<?php echo $row['excel_id']?>)>Update Tarif
</button>
        </td>
        <?php form_close(); ?>
<?php }}; ?>
        </tr>
    </table>

</body>
</html>

<script>
function update(excel_id)    {

        $.ajax({
         type: "POST",
         url: "<?php echo site_url('ajax/edit');?>/" + excel_id + "/" + $('#'+excel_id).val(),
         data: $(this).serialize(),
         dataType: 'json',
         success: function (data) {
            console.log(data); 
        }
        });
    };


</script>

i want to send the value '9000' which inside the input text into mysql. i don't know the syntax

</div>
  • 写回答

1条回答 默认 最新

  • weixin_33709364 2016-04-15 04:54
    关注

    try like this

                 $this->request->updatedata($excel_id,$tarif);
    

    instead of

                 $this->request->updatedata($tarif,$excel_id);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导
  • ¥15 docker模式webrtc-streamer 无法播放公网rtsp