• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sending a Code to an Email Address in CodeIgniter

#11
I can't get the finding of the code to work. I can get the email address and code inserted into the database.

And I've tried sending an email with the code from localhost but I guess that does not work so I'll leave that until I get a server.

I can copy the code from the database and paste it into the text box but I get this error - An uncaught Exception was encountered - Type: Error - Method name must be a string

This is the coding;

Controller

PHP Code:
class Code extends CI_Controller {

 public function 
index()
 {
 
$this->load->view('tempub');
 
$this->load->model('Code_model''code_model');
 
$code $this->input->post('code');
 if (
$this->$code() === 'pass_word'// An uncaught Exception was encountered - Type: Error - Method name must be a string
 
{
 
$this->load->view('username');
 }
 else
 {
 
$this->load->view('codeincorrect');
 }
 }


Model

PHP Code:
class Code_model extends CI_Model
{
 function 
__construct()
 {
 
parent::__construct();
 
$this->load->database();
 }
 public function 
find_code($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 TRUE;
 
$this->db->delete('pass_word'$code);
 }


Can somebody explain where I'm going wrong?
Reply

#12
You have this code in your controller:
PHP Code:
$code $this->input->post('code');
if (
$this->$code() === 'pass_word'

If you refer to $this-> .... it can either be a variable that has been declared for the class you're working in (the controller for instance), or a method ( = function) inside that class.
If it's a class level variable, it's $this->code. If it's a class level method, it's $this->code(). In both cases, $this->$code is wrong.

I think you simply want to check if the variable $code is equal to the literal string 'pass_word'.  So it should be:
PHP Code:
$code $this->input->post('code');
if (
$code === 'pass_word'
Reply

#13
(05-23-2017, 08:18 AM)Wouter60 Wrote: You have this code in your controller:
PHP Code:
$code $this->input->post('code');
if (
$this->$code() === 'pass_word'

If you refer to $this-> .... it can either be a variable that has been declared for the class you're working in (the controller for instance), or a method ( = function) inside that class.
If it's a class level variable, it's $this->code. If it's a class level method, it's $this->code(). In both cases, $this->$code is wrong.

I think you simply want to check if the variable $code is equal to the literal string 'pass_word'.  So it should be:
PHP Code:
$code $this->input->post('code');
if (
$code === 'pass_word'

OK, thanks but it loads this;

PHP Code:
$this->load->view('codeincorrect'); 

I want it to load that only if the code is wrong.

If the code is correct I want it to load

PHP Code:
$this->load->view('username'); 

There maybe something wrong in the Model.
Reply

#14
Your controller doesn't do anything with the model, except loading it. There is no call to the function find_code() in your controller.
Reply

#15
(05-23-2017, 02:02 PM)Wouter60 Wrote: Your controller doesn't do anything with the model, except loading it. There is no call to the function find_code() in your controller.

I need to be hand fed. I'm having to guess & test each step because I cant find anywhere to learn.

I've inserted this line into the controller below the model load;

PHP Code:
$this->find_code(); 

but get this error "Call to undefined method Code::find_code()"
Reply

#16
SOME HELP WOULD BE APPRECIATED.
Reply

#17
(05-24-2017, 10:23 PM)christaliise Wrote: SOME HELP WOULD BE APPRECIATED.

https://www.codeigniter.com/userguide3/o...arted.html
Reply

#18
(05-25-2017, 02:59 AM)Wouter60 Wrote:
(05-24-2017, 10:23 PM)christaliise Wrote: SOME HELP WOULD BE APPRECIATED.

https://www.codeigniter.com/userguide3/o...arted.html

The userguide is not the place to learn, it is designed for the "intermediate PHP programmer".
https://www.codeigniter.com/userguide3/t...usion.html

Every intermediate PHP programmer should be able to get the hang of CodeIgniter within a few days.
If you still have questions about the framework or your own CodeIgniter code, you can:
Check out our forums - Yeah right!
Reply

#19
If you have no basic knowledge of php, and you don't want to invest time to learn the basics of CodeIgniter, you won't get much help here. You say you need to be hand fed. That's not what you can expect here. Other users will be annoyed by questions that have an obvious answer in the CI documentation which is actually very good. There are few web frameworks so well documented as CI.
Reply

#20
(05-25-2017, 08:52 AM)Wouter60 Wrote: If you have no basic knowledge of php, and you don't want to invest time to learn the basics of CodeIgniter, you won't get much help here. You say you need to be hand fed. That's not what you can expect here. Other users will be annoyed by questions that have an obvious answer in the CI documentation which is actually very good. There are few web frameworks so well documented as CI.

I do have a basic knowledge of PHP and I have spent considerable time studying the basics of CodeIgniter, as I've managed to build 4 pages already, 2 complete, and I only ask questions when I'm absolutely exhausted from searching the Internet. So where are the "obvious answers"?
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.