我已经为此浪费了几个小时,我相信这很简单!
我对codeigniter很陌生。
基本上我想使用从我的表单中收到的值执行一个简单的 INSERT 到我的数据库中,这是我的观点:
<!DOCTYPE html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Page Title</title>
</head>
<body>
<div id="formage">
<?php echo validation_errors(); ?>
<?php echo form_open('../add_client'); ?>
<p>
<?php echo form_label('First Name', 'first_name');?>
<?php echo form_input('first_name', '', 'id="first_name"' );?>
</p>
<p>
<?php echo form_label('Last Name', 'second_name');?>
<?php echo form_input('second_name', '', 'id="second_name"' );?>
</p>
<p>
<?php echo form_label('Email Address', 'email_address');?>
<?php echo form_input('email_address', '', 'id="email_address"' );?>
</p>
<p>
<?php echo form_label('Password', 'password');?>
<?php echo form_password('password', '', 'id="password"' );?>
</p>
<p>
<?php echo form_label('Confirm Password', 'passwordconf');?>
<?php echo form_password('passwordconf', '', 'id="passwordconf"' );?>
</p>
<p>
<?php echo form_submit('submit', 'Add New Client');?>
</p>
<?php echo form_close(); ?>
</div>
这调用了我的控制器:
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class Add_client extends CI_Controller{
function __construct(){
parent::__construct();
}
function index(){
$this->load->library('form_validation');
$this->form_validation->set_rules('first_name', 'First Name', 'required');
$this->form_validation->set_rules('second_name', 'Second Name', 'required');
$this->form_validation->set_rules('email_address', 'Email Address', 'required|valid_email');
$this->form_validation->set_rules('password', 'Password', 'required|min_length(4)');
$this->form_validation->set_rules('passwordconf', 'Password', 'required|matches[password]');
if($this->form_validation->run() !== false){
$this->load->model('add_client_model');
$this->add_client_model->addUser(
$this->input->post('first_name'),
$this->input->post('second_name'),
$this->input->post('email_address'),
$this->input->post('password'));
}
$this->load->view('add_client_view');
}
}
它又从我的模型中调用 addUser 函数:
<?php
class Add_client_model extends CI_Model{
function __construct(){
}
public function addUser($fname, $sname, $email, $password){
$this->db->set('first_name', $fname);
$this->db->set('second_name', $sname);
$this->db->set('email_address', $email);
$this->db->set('pasword', sha1($name));
$this->db->insert('users');
}
}
我遇到的问题是,每当我提交表单并调用该函数时,它似乎都会像这样插入变量名(见第二行):
https://dl.dropbox.com/u/76853467/Picture%204.png
我似乎无法让它接受我插入到我的函数参数中的发布数据!
有什么建议么?非常感谢!