我想创建一个用户注册表单,在这里,我允许用户可以像谷歌联系人一样,随意放置电子邮件和电话。
我已经创建了一个表单,允许用户动态添加或删除电子邮件和电话的输入字段。这是它的图像:用户注册表
这是我使用的模型脚本。。
public function store_email() {
if (! $this->validate_email()) return FALSE;
$this->db->trans_begin();
try {
$this->db->insert($this->table_user, $this);
$id = $this->db->insert_id();
foreach ($this->email as $key => $value) $this->email[$key]['user_id'] = $id;
$this->db->insert_batch($this->table_email, $this->email);
} catch (Exception $e) {
return FALSE;
}
if ($this->db->trans_status() === FALSE)
{
$this->db->trans_rollback();
return FALSE;
} else {
$this->db->trans_commit();
return TRUE;
}
}
public function store_phone() {
if (! $this->validate_phone()) return FALSE;
$this->db->trans_begin();
try {
$this->db->insert($this->table_user, $this);
$id = $this->db->insert_id();
foreach ($this->phone as $key => $value) $this->phone[$key]['user_id'] = $id;
$this->db->insert_batch($this->table_phone, $this->phone);
} catch (Exception $e) {
return FALSE;
}
if ($this->db->trans_status() === FALSE)
{
$this->db->trans_rollback();
return FALSE;
} else {
$this->db->trans_commit();
return TRUE;
}
}
这是我使用的控制器脚本...
public function store() {
$this->model->first_name = $this->input->post('first_name', TRUE);
$this->model->middle_name = $this->input->post('middle_name', TRUE);
$this->model->last_name = $this->input->post('last_name', TRUE);
$this->model->email = [];
$this->model->phone = [];
foreach ($this->input->post('label_id', TRUE) as $key => $value) $this->model->email[$key]['label_id'] = $value;
foreach ($this->input->post('email', TRUE) as $key => $value) $this->model->email[$key]['email'] = $value;
foreach ($this->input->post('label_id', TRUE) as $key => $value) $this->model->phone[$key]['label_id'] = $value;
foreach ($this->input->post('phone', TRUE) as $key => $value) $this->model->phone[$key]['phone'] = $value;
if ($this->model->store_email() === TRUE) {
if ($this->model->store_phone() === TRUE) {
$notification = 'Register success! You may login now!';
} else {
$notification = 'Register fail!';
}
} else {
$notification = 'Register fail!';
}
$this->CI->session->set_flashdata('Success',$notification);
redirect(base_url().'login');
}
我运行这个代码,它给我错误说数组到字符串转换,我不能存储任何数据到数据库。
更新:
下面是我得到的错误:
A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: database/DB_query_builder.php
Line Number: 1496
Backtrace:
File: C:\xampp\htdocs\ci-master-detail-trans\application\models\Customer_model.php
Line: 103
Function: insert_batch
File: C:\xampp\htdocs\ci-master-detail-trans\application\controllers\Customer.php
Line: 50
Function: store
File: C:\xampp\htdocs\ci-master-detail-trans\index.php
Line: 292
Function: require_once
我用于此目的的表格:
在批处理插入代码之前添加此行
$phone_details = implode(',',$this->phone);
然后在批插入中进行如下更改
$this->db->insert_batch($this->table_phone, $phone_details); // phone number will be stored in , separated format i.e. 1234567890,3216549870
对于数组到字符串的转换错误,可以按如下方式使用内爆函数:
$string_version = implode(',', $original_array)
请编辑你的文章,并把整个错误,以便我们可以帮助你。
基本上,我正在尝试获取一个访问令牌,以便通过Usage Details API获取Azure成本中心数据。问题是,我似乎无法用azure正确配置我的服务主体。我有: 在Azure Active Directory中创建了已注册的应用程序 请求URL:获取:https://management.azure.com/subscriptions/{订阅id}/resourceGroupName/{res
我对Java和Spring3(过去8年主要使用PHP)还很陌生。我已经使用spring security 3来处理所有默认的userDetails和userDetailsService,我知道我可以通过使用以下命令访问控制器中登录用户的用户名: 但有两个问题我想不通: > 我希望在用户登录时存储许多其他用户详细信息(如DOB、性别等),并在以后通过控制器进行访问。我需要做什么才能使创建的userD
本文向大家介绍php用户注册信息验证正则表达式,包括了php用户注册信息验证正则表达式的使用技巧和注意事项,需要的朋友参考一下 下面这个正则验证用户名的方法原则是这样的用户名必须是由字母带数字带定划线组成了,下面一起来看看例子吧. 1.检查用户名是否符合规定“两位以上的字母,数字,或者下划线”,代码如下: 两位以上的字母,数字,或者下划线:^[a-zA-Z0-9_\x7f-\xff][a-zA-Z
问题内容: 我如何验证信用卡。我需要做检查。黑莓中有API可以做到吗? 问题答案: 您可以使用以下方法来验证信用卡号
我正在使用spring security的spring boot 2.2.4。我面临的问题是,每次我与新用户登录时,主要用户名都会重置为新登录用户的详细信息,为什么。然而,正如我所观察到的,会话ID仍然正确。我不理解这种行为。知道吗? 用户详情服务 UserDetails类