![]() |
Php errors - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Php errors (/showthread.php?tid=28355) |
Php errors - El Forum - 03-08-2010 [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> <? echo $result; ?> </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? Php errors - El Forum - 03-08-2010 [eluser]maria clara[/eluser] can you post your code ? Php errors - El Forum - 03-08-2010 [eluser]pigfox[/eluser] <?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> <? echo $result; ?> </h3> Php errors - El Forum - 03-09-2010 [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); Php errors - El Forum - 03-09-2010 [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> <? echo $result; ?> </h3> /controllers/contact.php <?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 */ Php errors - El Forum - 03-09-2010 [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); Php errors - El Forum - 03-09-2010 [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'); should be Code: $this->load->view('header'); or if you want to send through an array instead of an object: Code: $this->load->view('header'); Php errors - El Forum - 03-09-2010 [eluser]rdjs[/eluser] @SAS, echo doesn't need the (). Sure you knew this already, but didn't want anyone to copy your typo! ![]() Php errors - El Forum - 03-09-2010 [eluser]Suhas nazir[/eluser] @rdjs ,I knw bt if u used () with echo it will not cause an error...... Php errors - El Forum - 03-09-2010 [eluser]pigfox[/eluser] That worked. Thank you! |