Php 表单数据未在数据库中排序
我正在cakephp mvc体系结构中开发一个注册表单,但当我提交表单时,数据并没有存储在数据库中 数据库:Php 表单数据未在数据库中排序,php,cakephp,Php,Cakephp,我正在cakephp mvc体系结构中开发一个注册表单,但当我提交表单时,数据并没有存储在数据库中 数据库: CREATE TABLE users ( id INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY , username VARCHAR( 40 ) NOT NULL , password VARCHAR( 40 ) NOT NULL , email VARCHAR( 255 ) NOT NULL , first_name VARCHAR( 40
CREATE TABLE users (
id INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
username VARCHAR( 40 ) NOT NULL ,
password VARCHAR( 40 ) NOT NULL ,
email VARCHAR( 255 ) NOT NULL ,
first_name VARCHAR( 40 ) NOT NULL ,
last_name VARCHAR( 40 ) NOT NULL
)
模型类:
<?php
class User extends AppModel
{
var $name='User';
}
?>
视图类:
<html>
<form action="../users/register" method="post">
<p>Please fill out the form below to register an account.</p>
<label>Username:</label><input name="username" size="40" />
<label>Password:</label><input type="password" name="password" size="40"
/>
<label>Email Address:</label><input name="email" size="40"
maxlength="255" />
<label>First Name:</label><input name="first_name" size="40" />
<label>Last Name:</label><input name="last_name" size="40" />
<input type="submit" value="register" />
</form>
</html>
控制器类:
<?php
class UsersController extends AppController
{
function register(){
if (!empty($this->params['form']))
{
if($this->User->save($this->params['form']))
{
$this->flash('Registration Successful','/users/register');
}
else
{
$this->flash('Not succeeded','/users/register');
}
}
}
}
?>
请解决这个问题。试试看
$this->User->save$this->params['data']
或
$this->User->save$this->request->data 蛋糕2.X的溶液
查看文件
<?php
echo $this->Form->create('User', array(
'controller' => 'users', 'action'=>'register'
));
echo $this->Form->input('username', array(
'size'=>40,
'type' => 'text',
'placeholder'=>__('Your username'),
));
echo $this->Form->input('password', array(
'size'=>40,
'type' => 'password',
'placeholder'=>__('password'),
));
echo $this->Form->input('email', array(
'size'=>40,
'type' => 'email',
'placeholder'=>__('your@email.com'),
));
echo $this->Form->input('first_name', array(
'size'=>40,
'type' => 'text',
'placeholder'=>__('First name'),
));
echo $this->Form->input('last_name', array(
'size'=>40,
'type' => 'text',
'placeholder'=>__('Last name'),
));
echo $this->Form->end('Submit');
?>
您使用的是哪个版本的cakephp?我使用的是cakephp 2.4版本,您是否阅读了文档?因为您可以使用cakephp代码向数据库添加数据。。。是的,我已经阅读了mvc架构的文档。如果我运行上面的代码,我的浏览器屏幕上会出现空白屏幕吗?2上是否有调试模式?它显示错误消息,如缺少控制器用户中未定义的操作索引控制器如果我在控制器中提到该索引,我的浏览器中将显示空白屏幕。在此处更改路径$this->redirect'/;如果不想重定向,请删除该行。当不在对象上下文文件中时,它会使用$this显示错误消息:D:\xampp\htdocs\cakephp\app\Model\User.php行:9您有公共函数寄存器或函数寄存器第一行是正确的
public function register(){
if($this->request->is('post')){
if($this->User->save($this->request->data)) {
$this->Session->setFlash(__('Registered'));
$this->redirect('/');
} else {
$this->Session->setFlash(__('Something went wrong!'));
}
}
}