Welcome Guest, Not a member yet? Register   Sign In
Sending a Code to an Email Address in CodeIgniter
#3

(This post was last modified: 04-22-2017, 11:09 PM by christaliise.)

I'm having difficulty inserting the code into the database. I can get the email address inserted OK.

I searched "generate code with string_random();  see documentation about the string helper" in CodeIgniter's User Guide but could not get anything to work. But found another Random String which works if I insert it into the view page, but I can't get that into the database. I've tried many variations, including a separate Model Page but still can't get the code into the database.

This is my Controller Page;

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

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');
$this->email_model->insert_email($email);
//Works OK up to here
$code $this->$random_string();
$random_string chr(rand(65,90)) . rand(1,9) . chr(rand(65,90)) . rand(1,9) . chr(rand(65,90)) . chr(rand(65,90)); //This works in the view page
$this->code_model->insert_code($code);
}
}


This is my Model Page;

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

class 
Email_model extends CI_Model
{

function 
__construct()
{
parent::__construct();
$this->load->database();
}

public function 
insert_email($email)
{
$data = array(
'email_address' => $email,
);
$this->db->insert('tbl_members'$data);
return 
$this->db->insert_id();
}

public function 
insert_code($code)
{
$data = array(
'pass_word' => $code
);
$this->db->insert('tbl_members'$data);
return 
$this->db->insert_id();
}

Reply


Messages In This Thread
RE: Sending a Code to an Email Address in CodeIgniter - by christaliise - 04-21-2017, 07:25 AM



Theme © iAndrew 2016 - Forum software by © MyBB