Welcome Guest, Not a member yet? Register   Sign In
Php errors
#1

[eluser]pigfox[/eluser]
I get the following error:

A PHP Error was encountered
Severity: Notice
Message: Undefined variable: result
Filename: views/send.php
Line Number: 3

The code:
<h3>
&lt;?
echo $result;
?&gt;
</h3>

$result is set in the controller:
$this->load->view('send', $result);

My error reporting is commented out.
/*
ini_set('display_errors', 1);
ini_set('log_errors', 1);
ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
error_reporting(E_STRICT);
*/

Is this CI related or should I look deeper in my shared server?
#2

[eluser]maria clara[/eluser]
can you post your code ?
#3

[eluser]pigfox[/eluser]
&lt;?php

class Contact extends Controller
{

public function __construct()
{
parent::__construct();
}

function index()
{
$this->load->helper('form');
$this->load->view('header');
$this->load->view('contact_form');
$this->load->view('footer');
}

function send()
{
$this->load->library('email');
$name = $this->input->post('name', TRUE);
$email = $this->input->post('email2', TRUE);
$message = $this->input->post('message', TRUE);
$result= 'Your message was NOT sent';

if(isset($name) && isset($email) && isset($message))
{
$this->email->from($email, $name);
$this->email->to('[email protected]');
$this->email->subject($name.' sent you a msg from domain.com');
$message="Name $name\nEmail $email\nMessage $message";
$this->email->message($message);
$this->email->send();
$result= 'Thank you '.$name.', your message was NOT sent';
}

$this->load->view('header');
$this->load->view('send', $result);
$this->load->view('footer');
}

}
/* End of file contact.php */
/* Location: ./system/application/controllers/contact.php */

Views/send.php
<h3>
&lt;?
echo $result;
?&gt;
</h3>
#4

[eluser]rdjs[/eluser]
I think the problem is the way you are sending the data through to your view, try this instead:

$view->result = $result;
$this->load->view(‘send’, $view);
#5

[eluser]pigfox[/eluser]
Hello,
That triggered another error:
A PHP Error was encountered
Severity: Notice
Message: Use of undefined constant �send� - assumed '�send�'
Filename: controllers/contact.php
Line Number: 42
An Error Was Encountered
Unable to load the requested file: �send�.php

/views/send.php
<h3>
&lt;?
echo $result;
?&gt;
</h3>

/controllers/contact.php
&lt;?php

class Contact extends Controller
{
private $result;

public function __construct()
{
parent::__construct();
}

function index()
{
$this->load->helper('form');
$this->load->view('header');
$this->load->view('contact_form');
$this->load->view('footer');
}

function send()
{
$this->load->library('email');
$name = $this->input->post('name', TRUE);
$email = $this->input->post('email2', TRUE);
$message = $this->input->post('message', TRUE);
$result= 'Your message was NOT sent';

if(isset($name) && isset($email) && isset($message))
{
$this->email->from($email, $name);
$this->email->to('[email protected]');
$this->email->subject($name.' sent you a msg from mydomain.com');
$message="Name $name\nEmail $email\nMessage $message";
$this->email->message($message);
$this->email->send();
$result= 'Thank you '.$name.', your message was NOT sent';
}


$this->load->view('header');
$view->result = $result;
$this->load->view(‘send’, $result);
$this->load->view('footer');
}

}
/* End of file contact.php */
/* Location: ./system/application/controllers/contact.php */
#6

[eluser]Suhas nazir[/eluser]
$result= ‘Thank you ‘.$name.’, your message was NOT sent’;
instead of this u store the data like this
$data['result']=‘Thank you ‘.$name.’, your message was NOT sent’;
and then send
$this->load->view('send',$data);
and on the view u just echo the variable result
echo($result);
#7

[eluser]rdjs[/eluser]
You have not copied my code correctly. You have assigned $result to $view->result and still sent through $result into your view.

Code:
$this->load->view('header');
$view->result = $result;
$this->load->view('send', $result);
$this->load->view('footer');

should be

Code:
$this->load->view('header');
$view->result = $result;
$this->load->view('send', $view);
$this->load->view('footer');

or if you want to send through an array instead of an object:

Code:
$this->load->view('header');
$view['result'] = $result;
$this->load->view('send', $view);
$this->load->view('footer');
#8

[eluser]rdjs[/eluser]
@SAS, echo doesn't need the ().

Sure you knew this already, but didn't want anyone to copy your typo! Smile
#9

[eluser]Suhas nazir[/eluser]
@rdjs ,I knw bt if u used () with echo it will not cause an error......
#10

[eluser]pigfox[/eluser]
That worked.
Thank you!




Theme © iAndrew 2016 - Forum software by © MyBB