Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何检查数据库中的数据是否为真不在CodeIgniter中使用会话_Codeigniter - Fatal编程技术网

如何检查数据库中的数据是否为真不在CodeIgniter中使用会话

如何检查数据库中的数据是否为真不在CodeIgniter中使用会话,codeigniter,Codeigniter,我正在使用CodeIgniter,我有一个函数可以将电子邮件地址和代码插入数据库 我现在希望用户发布该代码,如果它是正确的,删除它,如果它是不正确的,让用户再试一次 我已经编辑了原始编码 电子邮件控制器-我删除了对会话的引用,并注释掉了发送电子邮件的内容,因为我只在localhost中进行测试。电子邮件功能运行良好。发布电子邮件功能后,我打开数据库并复制必须正确的代码 代码控制器-我已删除对会话的引用。我现在在代码视图中有一个电子邮件文本框,顺便说一句,它会自动插入电子邮件地址。然后我将代码粘贴

我正在使用CodeIgniter,我有一个函数可以将电子邮件地址和代码插入数据库

我现在希望用户发布该代码,如果它是正确的,删除它,如果它是不正确的,让用户再试一次

我已经编辑了原始编码

电子邮件控制器-我删除了对会话的引用,并注释掉了发送电子邮件的内容,因为我只在localhost中进行测试。电子邮件功能运行良好。发布电子邮件功能后,我打开数据库并复制必须正确的代码

代码控制器-我已删除对会话的引用。我现在在代码视图中有一个电子邮件文本框,顺便说一句,它会自动插入电子邮件地址。然后我将代码粘贴到“代码”文本框中

但是,尽管代码是正确的,但选择的是视图('code不正确'),而不是视图('username')

谁能告诉我怎么了

电子邮件控制器

class Email extends CI_Controller
{
public function index()
{
$this->load->model('Email_model', 'email_model');
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('email', 'email', 'required|min_length[10]|max_length[40]|valid_email|is_unique[tbl_members.email_address]', array(
'required' => 'You have not entered an %s address.', 'min_length' => 'Your %s address must be a minimum of 10 characters.',
'max_length' => 'Your %s address must be a maximum of 40 characters.', 'valid_email' => 'You must enter a valid %s address.',
'is_unique' => 'That %s address already exists in our Database.'));
if ($this->form_validation->run() == FALSE) // The email address does not exist.
{
$this->load->view('email');
}
else
{
$email = $this->input->post('email');
$random_string = chr(rand(65,90)) . rand(1,9) . chr(rand(65,90)) . rand(1,9) . chr(rand(65,90)) . chr(rand(65,90));
$code = $random_string;
$this->email_model->insert_email($email, $code);
/*
$this->load->library('email');
$this->email->from('<?php echo WEBSITE_NAME; ?>', '<?php echo WEBSITE_NAME; ?>');
$this->email->to('$email');
$this->email->subject('Code.');
$this->email->message('Select & Copy this code, then return to the website. - ','$code');
$this->email->send();
*/
$this->load->view('code');
}
}
}
class Code extends CI_Controller
{
public function index()
{
$this->load->model('Code_model', 'code_model');
$email = $this->input->post('email');
$code = $this->input->post('code');
$result = $this->code_model->find_code($email, $code);
if ($result)
{
$this->load->view('username');
}
else
{
$this->load->view('codeincorrect');
}
}
}
public function index()
{

  $this->load->model('Code_model', 'code_model');

  $code = $this->input->post('code');
  // Need to email here.
   $email= $this->input->post('email');
   $result = $this->code_model->find_code($code,$email);

  if ($result)
  {
    $this->load->view('username');
  }
  else
  {
    $this->load->view('codeincorrect');
  }
}
代码控制器

class Email extends CI_Controller
{
public function index()
{
$this->load->model('Email_model', 'email_model');
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('email', 'email', 'required|min_length[10]|max_length[40]|valid_email|is_unique[tbl_members.email_address]', array(
'required' => 'You have not entered an %s address.', 'min_length' => 'Your %s address must be a minimum of 10 characters.',
'max_length' => 'Your %s address must be a maximum of 40 characters.', 'valid_email' => 'You must enter a valid %s address.',
'is_unique' => 'That %s address already exists in our Database.'));
if ($this->form_validation->run() == FALSE) // The email address does not exist.
{
$this->load->view('email');
}
else
{
$email = $this->input->post('email');
$random_string = chr(rand(65,90)) . rand(1,9) . chr(rand(65,90)) . rand(1,9) . chr(rand(65,90)) . chr(rand(65,90));
$code = $random_string;
$this->email_model->insert_email($email, $code);
/*
$this->load->library('email');
$this->email->from('<?php echo WEBSITE_NAME; ?>', '<?php echo WEBSITE_NAME; ?>');
$this->email->to('$email');
$this->email->subject('Code.');
$this->email->message('Select & Copy this code, then return to the website. - ','$code');
$this->email->send();
*/
$this->load->view('code');
}
}
}
class Code extends CI_Controller
{
public function index()
{
$this->load->model('Code_model', 'code_model');
$email = $this->input->post('email');
$code = $this->input->post('code');
$result = $this->code_model->find_code($email, $code);
if ($result)
{
$this->load->view('username');
}
else
{
$this->load->view('codeincorrect');
}
}
}
public function index()
{

  $this->load->model('Code_model', 'code_model');

  $code = $this->input->post('code');
  // Need to email here.
   $email= $this->input->post('email');
   $result = $this->code_model->find_code($code,$email);

  if ($result)
  {
    $this->load->view('username');
  }
  else
  {
    $this->load->view('codeincorrect');
  }
}
代码模型

class Code_model extends CI_Model
{
function __construct()
{
parent::__construct();
$this->load->database();
}
public function find_code($email, $code)
{
$this->db->select('user_id');
$this->db->where('email_address', $email);
$this->db->where('pass_word', $code);
$code = $this->db->get('tbl_members');
if ($code->result())
{
return $this->db->delete('pass_word', $code);
}
}
}
这是代码视图中的编码,可能导致问题

<style type="text/css"> .email-address { position: fixed; width: 100%; text-align: center; top: 30%; } </style>
<div class="email-address">
<input type="text" name="email" value="<?php echo set_value('email'); ?>" style="width: 18%; height: 5mm"; />
<style type="text/css"> .code { position: fixed; width: 100%; text-align: center; top: 55%; } </style>
<div class="code">
<input type="email" class="form-control" name="code" style="width: 15mm; height: 5mm"; />
<a href="<?php echo BASE_URL . 'username'; ?>"></a></div>
<?php echo form_open('code'); ?>
<style type="text/css"> .submit { position: fixed; width: 100%; text-align: center; top: 65%; } </style>
<div class="submit">
<input type="submit" class="btn btn-primary" value="Submit" />
</form></div>
。电子邮件地址{位置:固定;宽度:100%;文本对齐:居中;顶部:30%;}

因此,您的控制器正确调用模型,但您没有检查模型功能,也没有发送电子邮件字段

所以这应该是正确的:

控制器:

public function index()
{
    $this->load->model('Code_model', 'code_model');
    $code = $this->input->post('code');
    $email= $this->input->post('email');

    if ($this->code_model->find_code($code, $email)) {
        $this->load->view('username');
    } else {
        $this->load->view('codeincorrect');
    }

}
public function find_code($code, $email)
{
    $this->db->select('user_id');
    $this->db->where('email_address', $email);
    $this->db->where('pass_word', $code);
    $code = $this->db->get('tbl_members')->result();
    if ($code->num_rows() >= 1) {
        $this->db->delete('pass_word', $code);
    }

}
型号:

public function index()
{
    $this->load->model('Code_model', 'code_model');
    $code = $this->input->post('code');
    $email= $this->input->post('email');

    if ($this->code_model->find_code($code, $email)) {
        $this->load->view('username');
    } else {
        $this->load->view('codeincorrect');
    }

}
public function find_code($code, $email)
{
    $this->db->select('user_id');
    $this->db->where('email_address', $email);
    $this->db->where('pass_word', $code);
    $code = $this->db->get('tbl_members')->result();
    if ($code->num_rows() >= 1) {
        $this->db->delete('pass_word', $code);
    }

}
注意: 如果您尝试的是密码登录,那么您不应该这样做。请查看此示例:

请尝试

内部控制器

class Email extends CI_Controller
{
public function index()
{
$this->load->model('Email_model', 'email_model');
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('email', 'email', 'required|min_length[10]|max_length[40]|valid_email|is_unique[tbl_members.email_address]', array(
'required' => 'You have not entered an %s address.', 'min_length' => 'Your %s address must be a minimum of 10 characters.',
'max_length' => 'Your %s address must be a maximum of 40 characters.', 'valid_email' => 'You must enter a valid %s address.',
'is_unique' => 'That %s address already exists in our Database.'));
if ($this->form_validation->run() == FALSE) // The email address does not exist.
{
$this->load->view('email');
}
else
{
$email = $this->input->post('email');
$random_string = chr(rand(65,90)) . rand(1,9) . chr(rand(65,90)) . rand(1,9) . chr(rand(65,90)) . chr(rand(65,90));
$code = $random_string;
$this->email_model->insert_email($email, $code);
/*
$this->load->library('email');
$this->email->from('<?php echo WEBSITE_NAME; ?>', '<?php echo WEBSITE_NAME; ?>');
$this->email->to('$email');
$this->email->subject('Code.');
$this->email->message('Select & Copy this code, then return to the website. - ','$code');
$this->email->send();
*/
$this->load->view('code');
}
}
}
class Code extends CI_Controller
{
public function index()
{
$this->load->model('Code_model', 'code_model');
$email = $this->input->post('email');
$code = $this->input->post('code');
$result = $this->code_model->find_code($email, $code);
if ($result)
{
$this->load->view('username');
}
else
{
$this->load->view('codeincorrect');
}
}
}
public function index()
{

  $this->load->model('Code_model', 'code_model');

  $code = $this->input->post('code');
  // Need to email here.
   $email= $this->input->post('email');
   $result = $this->code_model->find_code($code,$email);

  if ($result)
  {
    $this->load->view('username');
  }
  else
  {
    $this->load->view('codeincorrect');
  }
}
模型中

public function find_code($code,$email)
{
$this->db->select('user_id');
$this->db->where('email_address', $email);
$this->db->where('pass_word', $code);
$code = $this->db->get('tbl_members');
if ($code->result()) {
$this->db->delete('pass_word', $code);
}
}

谢谢Jewel Mia博士,我尝试过你建议的改变,但出现了这个错误;遇到未捕获的异常类型:错误消息:调用未定义的函数form_open()文件名:C:\xampp\htdocs\application\views\codeError.php,该文件在视图中引用此文件;以上与我所做的其他函数一起工作$此->加载->查看('code不正确');鉴于,代码是正确的,应转到$此->加载->查看('username');该视图是用户名和密码的下一步。它无法工作,因为它加载$this->load->View('code不正确');是的,因为如果不响应$result中的值,则加载$this->load->view('code不正确');如果响应值在$result中,则加载$this->load->view('username');您想让我检查什么来找到响应值?谢谢Web先生,我已经尝试了您建议的更改,但出现了此错误;遇到未捕获的异常类型:ParseError消息:语法错误,意外的文件结尾,预期函数(T_函数)引用它$此->数据库->删除('pass_word',$code);在模型中。作为对您的查询的响应,不,我不尝试使用密码登录。我试图首先让用户发布一个电子邮件地址,我成功地将电子邮件地址和代码插入到数据库中。我想发送一封带有代码的电子邮件,但这将不得不等到我有了服务器。但是,我可以从数据库中复制代码,然后通过subject函数发布。代码只是暂时保存在pass_word字段中。下一步$this->load->view('username');是永久用户名和密码。好的,但我现在得到这个错误;类型:错误消息:调用数组文件名:C:\xampp\htdocs\application\models\Code\u model.php上的成员函数num\u rows(),该函数表示if($Code->num\u rows()>=1){I will will moother。