【发布时间】:2020-06-23 05:05:20
【问题描述】:
如何为会员编号制作自动生成的代码。我使用 Codeigniter 框架。但它显示了一些错误,并且所有数据都成功输入到数据库中,除了“会员编号”在错误中突出显示,如下图所示。
这是我的代码:
//Model
public function customer_insert($table, $data)
{
$query = $this->db->insert($table, $data);
return $query;
}
public function customer_getByLastId()
{
$query = $this->db->query("SELECT customer_id FROM customer where customer_id=last_insert_id()");
return $query;
}
public function customer_update($id, $table, $data)
{
$query = $this->db->where('customer_id', $id);
$query = $this->db->update($table, $data);
return $query;
}
//Controller
public function add()
{
$name = strip_tags($this->input->post('i_name'));
$ktp = strip_tags($this->input->post('i_ktp'));
$email = strip_tags($this->input->post('i_email'));
$gender = strip_tags($this->input->post('i_gender'));
$phone = strip_tags($this->input->post('i_phone'));
$address = strip_tags($this->input->post('i_address'));
// Input Array
$data = array(
'name' => $name,
'ktp' => $ktp,
'email' => $email,
'gender' => $gender,
'phone' => $phone,
'address' => $address
);
// Insert ke Database
$x = $this->customer_model->customer_cek($ktp);
if ($x == Null) {
$this->customer_model->customer_insert('customer', $data);
$id = $this->customer_model->customer_getByLastId();
$char = "MEM";
$no_member = $char . sprintf("%09s", $id);
$data = array(
'no_member' => $no_member
);
$this->customer_model->customer_update($id, 'customer', $data);
echo '<script language=JavaScript>alert("Input Berhasil")
onclick=history.go(-0);</script>';
} else {
echo '<script language=JavaScript>alert("Gagal!! customer telah tersimpan sebelumnya karena Nama atau dan No. Hp sama!")
onclick=history.go(-1);</script>';
}
}
错误如下:
遇到 PHP 错误,严重性:4096
消息:CI_DB_mysqli_result 类的对象无法转换为 字符串
文件名:admin/Customer.php
行号:46
回溯:
文件: C:\xampp\htdocs\tokobuku\application\controllers\admin\Customer.php 行:46 功能:sprintf
文件:C:\xampp\htdocs\tokobuku\index.php 行:315 功能: 需要一次
遇到 PHP 错误,严重性:4096
消息:CI_DB_mysqli_result 类的对象无法转换为 一个字符串
文件名:数据库/DB_query_builder.php
行号:2442
回溯:
文件:C:\xampp\htdocs\tokobuku\application\models\Customer_model.php 行:32 功能:更新
文件: C:\xampp\htdocs\tokobuku\application\controllers\admin\Customer.php 行:51 功能:customer_update
文件:C:\xampp\htdocs\tokobuku\index.php 行:315 功能: 需要一次
发生数据库错误错误号:1064
您的 SQL 语法有错误;检查手册 对应于您的 MariaDB 服务器版本,以便使用正确的语法 第 2 行的 '' 附近
更新
customerSETno_member= 'MEM000000000' WHEREcustomer_id文件名:C:/xampp/htdocs/tokobuku/system/database/DB_driver.php
行号:691
【问题讨论】:
-
你想找回自动生成的Id吗?
-
您能说得更具体些吗?你能分享一下错误吗?
-
请在您的问题中直接添加您想要审核的代码,发布图片会使获得概览变得更加困难。如上所述,分享您遇到的错误
标签: php codeigniter auto-generate