gpt4 book ai didi

php - 将ajax值发送到mysql

转载 作者:行者123 更新时间:2023-11-29 21:08:05 24 4
gpt4 key购买 nike

我有 2 个表:'excel' enter image description here和“请求”enter image description here

我从输入文本中获取值,现在我想将“9000”值发送到“excel”表中的“关税”字段。

enter image description here

这是我的 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);

}
}

我的模型:

<?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();
}
}

这是我的ajax,在 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>

我想将输入文本中的值“9000”发送到mysql。我不知道语法

最佳答案

尝试这样

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

而不是

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

关于php - 将ajax值发送到mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36637325/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com