我是PHP和Codeigniter的新手。实际上,我是一个Windows程序员,想要探索开源世界。我正在尝试使用Codeigniter框架在PHP中制作一个带有bacoffice的网站。现在,我正在尝试在以后可以登录系统的数据库上注册用户。但是我无法获取表单上文本框字段中写入的数据并将其传递给我的变量。
这是我的控制器:
public function InsertUser(){
$this->load->model('sdcadmin/loginmodel');
if($this->input->post()){
$nome = $this->input->post('Nome') ? $this->input->post('Nome') : null;
$email = $this->input->post('Email') ? $this->input->post('Email') : null;
$utlIns = 'Sistema';
$dataIns = getdate(1);
$utlAlt = 'Sistema';
$dataAlt = getdate(1);
$senha = $this->input->post('Senha') ? $this->input->post('Senha') : null;
$repeteSenha = $this->input->post('Senharep') ? $this->input->post('Senharep') : null;
if($senha != $repeteSenha){
echo 'Passwords doesn't match!';
}
else
{
$this->loginmodel->InsertUser($nome, $email, $senha, $utlIns, $dataIns, $utlAlt, $dataAlt);
echo 'Success!';
}
}
else
{
echo 'Not Working';
}
}
这是我的表格:
<form method="POST" action="Login/InsertUser">
<img src="<?php echo base_url() ?>Images/logo.png"/>
<div>
<input type="text" placeholder="Nome" required="" id="Nome" />
</div>
<div>
<input type="text" placeholder="Email" required="" id="Email" />
</div>
<div>
<input type="password" placeholder="Palavra-Passe" required="" id="Senha" />
</div>
<div>
<input type="password" placeholder="Repetir Palavra-Passe" required="" id="Senharep" />
</div>
<div>
<input type="submit" value="Registar" id="btnSub" />
</div>
</form>
在我对此问题的调查中,可能是我的 .htaccess 文件阻止了所有 POST 请求,但我不确定。
这是我的.htaccess文件:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /dcm/
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond $1 !^(index'.php|images|robots'.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
#This code was added in atemp to allow posts request, but not working
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_METHOD} POST
# allow localhost
RewriteCond %{REMOTE_ADDR} !127'.0'.0'.1$
RewriteRule ^ - [F]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
你能帮我吗?
多谢。
您需要将"name"属性添加到每个输入类型字段。
<div>
<input type="text" placeholder="Nome" required="" id="Nome" name="Nome" />
</div>
<div>
<input type="text" placeholder="Email" required="" id="Email" name="Email" />
</div>
<div>
<input type="password" placeholder="Palavra-Passe" required="" id="Senha" name="Senha"/>
</div>
<div>
<input type="password" placeholder="Repetir Palavra-Passe" required="" id="Senharep" name="Senharep" />
</div>
您错过了向输入字段添加添加名称属性。检查下面并更正它。
<div>
<input type="text" placeholder="Nome" required="" id="Nome" name="Nome" />
</div>
<div>
<input type="text" placeholder="Email" required="" id="Email" name="Email" />
</div>
<div>
<input type="password" placeholder="Palavra-Passe" required="" id="Senha" name="Senha"/>
</div>
<div>
<input type="password" placeholder="Repetir Palavra-Passe" required="" id="Senharep" name="Senharep" />
</div>
将名称属性添加到输入字段。
好吧,我现在感觉很傻。我以为它是按 ID 映射的,而不是从名称属性映射的。你没事吧。
成功了!
谢谢!