不使用codeigniter保存数据

时间:2015-08-28 13:44:26

标签: codeigniter

您好我正在尝试从我的codeigniter表单中将数据插入到mysql数据库中,但它无法正常工作,而是将其重定向回wampserver主页。我正在使用wampserver和windows 2008操作系统。早些时候我已经改变了httpd.conf端口听8080,因为wamp不能正常工作。 我的数据库是;

   CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(32) NOT NULL,
`email` varchar(32) NOT NULL,
`password` varchar(32) NOT NULL,
`gender` varchar(8) NOT NULL,
`registered` varchar(16) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=6 ;


my model is:
<?php if ( ! defined('BASEPATH')) exit('No direct script access   allowed');
class User_model extends CI_Model {
public function __construct()
{
parent::__construct();
}
public function add_user()
{
$data=array(
'username'=>$this->input->post('username'),
'email'=>$this->input->post('email'),
'password'=>md5($this->input->post('password')),
'gender'=>$this->input->post('gender'),
'registred'=>time()
);
$this->db->insert('users',$data);
return true;
}
}

my controller is:
<?php if ( ! defined('BASEPATH')) exit('No direct script access   allowed');
class User extends CI_Controller {
public function index()
{
$this->load->view('register_view');
}
public function register()
{ 
$this->load->view('register_view');//loads the register_view.php file in views folder
}
public function do_register()
{
if($this->input->post('register'))//$_POST["register"];
{
$this->load->model('user_model');//loads the user_model.php file in     models folder
if($this->user_model->add_user())
{
echo "hi ".$this->input->post('username')." Registred successfully" ;
}
else
{
echo "Registration failed";
}
}
}

}

my view is:

<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-    8"></head>
<body>
<div class="container">
<table>
<tr>
<form action="<?=site_url('user/do_register')?>" method="post">
<td><label for="username">User Name</label>
<input type="text" name="username"/></td>
<tr><td><label for="email">Email</label>
<input type="text" name="email"/></td></tr>
<tr><td><label for="password">Password</label>
<input type="password" name="password"/></td><tr>

<tr><td><label for="gender">Gender</label>
<input type="radio" name="gender" value="male"/>male
<input type="radio" name="gender" value="female"/>female</tr></td>
<tr><td><input type="submit" value="Sign up" name="register"/>
</tr></td>
</tr>
</form>
</table>
</div>
</body>
</html>
kindly assist me remove this error

0 个答案:

没有答案