Php codeigniter插入仅插入变量名
我在这件事上浪费了好几个小时,我相信这件事很简单 我对codeigniter是个新手 基本上,我想使用从我的表单接收到的值执行一个简单的数据库插入。以下是我的视图:Php codeigniter插入仅插入变量名,php,mysql,forms,codeigniter,Php,Mysql,Forms,Codeigniter,我在这件事上浪费了好几个小时,我相信这件事很简单 我对codeigniter是个新手 基本上,我想使用从我的表单接收到的值执行一个简单的数据库插入。以下是我的视图: <!DOCTYPE html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8"> <title>Page Title</title> </head>
<!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>
页面标题
嗯。。。。我有时也会有零星的问题,但似乎在CI 2中
但是,使用好的旧$\u POST对象访问它怎么样?毕竟,这是CI获取数据的地方。尝试以下方法:
$data = array(
'first_name' => $fname,
'second_name' => $sname,
'email_address' => $email,
'password' => sha1($password)
);
$this->db->insert('users', $data);
您是否使用echo或FireHP(如果正在使用)检查变量值
确保参数在模型接受post时向模型发送适当的值。我在控制器中看不到表单帮助器。也许你已经自动上映了?如果没有,请尝试将其添加到其中
$this->load->helper('form');
我知道这是一种方法,但您尝试过:$this->db->insert('users',array('first\u name'=>$fname,'second\u name'=>sname,'email\u address',=>$email,'password'=>sha1($name));也许set方法有一个bug。顺便说一句,密码字段集合中有一个错误。您的表中的密码为2个S。感谢您的帮助,我已修改了错误的拼写并插入了数组,但仍然不走运。这可能与函数的调用方式有关吗?添加到模型中的_构造函数:parent::_构造()代码>尝试了所有建议,但仍然一无所获。现在我已经做了一些调整,当我调用控制器$this->add_client_model->add_user()中的函数时;我收到一张空白页,没有显示我呼叫的任何echo/print\r。谢谢回复!不幸的是,仍然返回变量名而不是值。对于调试,请在$data变量之后添加“print\r($data);exit;”。
$data = array(
'first_name' => $fname,
'second_name' => $sname,
'email_address' => $email,
'password' => sha1($password)
);
$this->db->insert('users', $data);
$this->load->helper('form');