gpt4 book ai didi

php - 我如何在 Codeigniter 中用 2 个或更多表填充数据库

转载 作者:行者123 更新时间:2023-11-29 19:13:54 25 4
gpt4 key购买 nike

i have problem, i want make a registration page, but i want fill data not just from 1 table but 2, i have the code like this :

<?php

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

class Pendaftaran2 extends CI_Controller {

public function daftar()
{
if(isset($_POST['pendaftaran'])){
$this->form_validation->set_rules('email','Email','required|is_unique[user.email]');
$this->form_validation->set_rules('password','password','required|min_length[5]');
$this->form_validation->set_rules('password2','konformasi password','required|min_length[5]|matches[password]');

//if form validation true
if($this->form_validation->run() == TRUE){
echo 'form validated';
$email = $this->input->post('email');
$pass = md5($this->input->post('password'));


$data = array(
'email' => $email,
'password' => $pass
);
$this->db->insert('user',$data);

$this->session->set_flashdata("success","your account has been created");
redirect('pendaftaran2/daftar','refresh');

}
}

//load view
$this->load->view('view_pendaftaran2');
$this->load->view('footer');
}
}

how to add the seconds table? and i want the button just 1 button to proccess the data

note : the name of second table is "personal_data" with field (name, birth and address)

最佳答案

您应该在同一表单上添加这些字段,并创建这些字段的另一个数组以供插入。所以你更新后的函数如下所示:

public function daftar()
{
if(isset($_POST['pendaftaran'])){
$this->form_validation->set_rules('email','Email','required|is_unique[user.email]');
$this->form_validation->set_rules('password','password','required|min_length[5]');
$this->form_validation->set_rules('password2','konformasi password','required|min_length[5]|matches[password]');

//if form validation true
if($this->form_validation->run() == TRUE){
echo 'form validated';
$email = $this->input->post('email');
$pass = md5($this->input->post('password'));


$data = array(
'email' => $email,
'password' => $pass
);
$this->db->insert('user',$data);
$personal_data = array(
'name' => $this->input->post('name'),
'birth' => $this->input->post('birth'),
'address'=>$this->input->post('birth')
);
$this->db->insert('personal_data',$personal_data);

$this->session->set_flashdata("success","your account has been created");
redirect('pendaftaran2/daftar','refresh');

}
}

//load view
$this->load->view('view_pendaftaran2');
$this->load->view('footer');
}

关于php - 我如何在 Codeigniter 中用 2 个或更多表填充数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42871397/

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