0

I want to get the value of column 'no' from the database and after that i want to mail this value to the user, but i got some error..

Here is the query which i have written for getting the value in the model and the function sendmail() which i have written to send the mail to the user in the controller..

Model: User_model

public function get_client_id()
{   

    $email = $this->input->post('email');
    $query = $this->db->query("SELECT no FROM users WHERE email = '$email' LIMIT 1");
    $result = $query->result_array();
    $value = mysql_fetch_object($result);
    $_SESSION['myid'] = $value->no;
}

Controller: Users.php

public function sendmail()
    {
        $config = Array(
        'protocol' => 'smtp',
        'smtp_host' => 'ssl://smtp.gmail.com',
        'smtp_port' => '465',
        'smtp_user' => 'something@gmail.com',
        'smtp_pass' => '******',
        'mailtype' => 'html',
        'charset' => 'iso-8859-1',
        'wordwrap' => TRUE
        );

        $data = $this->user_model->get_client_id();

        $message = print($_SESSION['myid']);


        $this->load->library('email', $config);
        $this->email->from('dharavihol119@gmail.com', 'Dhara Vihol');
        $this->email->to($_SESSION["email"]);

        $this->email->subject('You have successfully signed up');
        $this->email->message($message);


        if ( ! $this->email->send())
        {
            echo "There is some error!";
            echo $this->email->print_debugger();
        }
        else
        {
            echo "Mail is sent successfully";
            echo $this->email->print_debugger();
        }


    }

And these errors are being shown...

https://i.stack.imgur.com/vqAyR.png

But the mail is sent to the user and it always prints the 1 into the mail.

Please help me.. :(

Dhara Vihol
  • 602
  • 5
  • 26

2 Answers2

1

If you are using Codeigniter then why are you using mysql_fetch_object ??

Please change your code as below :

In your model

public function get_client_id()
{   

    $email = $this->input->post('email');
    $query = $this->db->query("SELECT no FROM users WHERE email = '$email' LIMIT 1");
$query = $this->db->get();
    $result = $query->row();
   return $result->no;
}

In your controller, Instead of

 $data = $this->user_model->get_client_id();

    $message = print($_SESSION['myid']);

use this

 $message = $this->user_model->get_client_id();
Drudge Rajen
  • 7,584
  • 4
  • 23
  • 43
1

In CodeIgniter you don't need to call mysql_fetch_object() as CodeIgniter has all the database layer written for you, the call you made just before will return an array with the results in it already ($result = $query->result_array();).

To properly use CodeIgniter's database layer, take the following for example:

public function get_client_id()
{   
    $email = $this->input->post('email');
    $query = $this->db->query("SELECT no FROM users WHERE email = '$email' LIMIT 1");
    $result = $query->row(); 
    return $result->no;
}

This will get the first row of your query response and return just the value no from the result.

Then in your sendmail() function you can change:

$data = $this->user_model->get_client_id();

$message = print($_SESSION['myid']);

to simply

$message = $this->user_model->get_client_id();

There is no need to pass the id in the SESSION array, unless you're storing it there for later use (in which case go right ahead! Just add that code back to my example code)

AlienHoboken
  • 2,750
  • 20
  • 23