php - both IF and ELSE are executed -- needs some help to spot the mistakes -


i made question in if else display 2 views on 1 function called thread , have tried fix suggested problem remains. hope me...it both of has inside "if" , has inside "else" ?

i have got little problem redirect function, have controller function named "someview" , created view file of same name (someview.ctp) controller function stuff(query data model). can described follows

function someview() {     $result=$this->user->getdatafrommodel();     if(!empty($result))     {         //do                     sendmail(.....);     }     else     {         $this->redirect(array('action'=>'usernotexist'));     } }  function usernotexist() {     $this->loadskin(); } 

i created page named "usernotexist.ctp" display information when specified user doesn't exist in database system. however, previous function (someview) execute "if" , "else" both after called. if eliminate "else" part in function, works correctly me; page named "someview.ctp" displayed. $result value returned getdatafrommodel function correct. thank help.

update
works:

    function someview() {     $result=$this->user->getdatafrommodel();             print_r($result);             exit();     if(!empty($result))     {         //do     }     else     {         $this->redirect(array('action'=>'usernotexist'));     } }  function usernotexist() {     $this->loadskin(); } 

this prints empty array.

    function someview() {     $result=$this->user->getdatafrommodel();             print_r($result);     if(!empty($result))     {         //do     }     else     {         $this->redirect(array('action'=>'usernotexist'));     } }  function usernotexist() {     $this->loadskin(); } 

[update]

what see after click link in view called "folder/subfolder/someview" call controller method described above, page in "else" redirected. in if part include "sendmail" function send email account. sendmail works. odd thing understand. if else both executed.

what right after user click link activate controller method (someview), if query returns empty record, directed page "usernotexist" or send him email otherwise.

for concern agree post original source code, thinking sendmail function might making mistake somewhere can not @ present recognize place.

here it

    function newpassword()     {         $this->loadskinforaction();         $result=$this->ewtuser->get_user_from_email($_post['email']);          if(!empty($result))         {             $userid = $result[0]['ewt_users']['id'];             $password=$this->ewtuser->get_and_change_user_password($_post['email']);                         $mail="your new password is: ".$password."<br/>please use next login.<br/>you recommended change password again in 'personal profile' section.";             $this->sendmail($userid,$mail,$_post['email']);          }         else         {             //print_r($result);             $this->redirect(array('action'=>'userexists'));         }     }      function userexists()     {         $this->loadskinforaction();          }  

and model function query data

function get_and_change_user_password($email)     {         $password=$this->genrandstr();         $sql=sprintf("update ewt_users set password='%s' email='%s'",md5($password),$email);         $this->query($sql);         return $password;     } 

and here sendmail function,

function sendmail($userid, $reportcontent,$email){         //if($this->session->read($this->_username))         {             $this->loadmodel('ewtmailtemplate');             $this->loadmodel('ewtuser');             $this->loadmodel('ewtsetting');             $this->autorender = false;              $date = date("y-m-d");             $userinfo = $this->ewtuser->read(null, $userid);             $fullname = $userinfo['ewtuser']['fullname'];             $lastname = $userinfo['ewtuser']['lastname'];             $mailtempl = $userinfo['ewtuser']['mailtempl'];             if ($mailtempl == 0) {                 $mailtempl = 1;             }              $setting = $this->ewtsetting->find('first');             $mailhost = $setting['ewtsetting']['mailhost'];             $mailuser = $setting['ewtsetting']['mailuser'];             $mailpass = $setting['ewtsetting']['mailpass'];             //$reportmail = $setting['ewtsetting']['reportmail'];             $reportmail=$email;             $bodymail = $this->ewtmailtemplate->read(null, $mailtempl);             //$header = $bodymail['ewtmailtemplate']['header'];             //$footer = $bodymail['ewtmailtemplate']['footer'];             //$title = $bodymail['ewtmailtemplate']['title'];             $subject="new login password working time system";             //$subject = $lastname . " " . str_replace("[date]", $date, $title);             //$header = str_replace("[lastname]", $lastname, $header);             //$header = str_replace("[date]", $date, $header);             //$footer = str_replace("[lastname]", $lastname, $footer);              //$content = '<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><html><head><meta http-equiv="content-type" content="text/html; charset =utf-8" /></head><body>'.$header ."<br />" . $reportcontent . "<br />" .  $footer . '</body></html>';              $content = '<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><html><head><meta http-equiv="content-type" content="text/html; charset =utf-8" /></head><body>'."<br />".$reportcontent."<br />".'</body></html>';              $this->email->to = $reportmail;             $this->email->charset = 'utf-8';             $this->email->from = sprintf("%s <%s>", $fullname, $mailuser);             $this->email->replyto = sprintf("%s <%s>", $fullname, $mailuser);             $this->email->subject = $subject;             $this->email->sendas ='html';             $smtp = array(                         'port'=>25,                         'host'=>$mailhost,                         'timeout'=>99,                         'username'=>$mailuser,                         'password'=>$mailpass             );             $this->email->smtpoptions = $smtp;             $this->email->delivery = 'smtp';              if ($this->email->send($content)) {                 $this->redirect('newpassword');                      } else {                 $this->redirect('userexists');             }              $smtp_error = $this->email->smtperror;             if (strlen($smtp_error)>0){                 $this->session->setflash($smtp_errors);             }         }     } 

again, it executes both if , else branches thank concern , i'd love hear comments or advice :-)

wow post long. can make phylogenetic tree! :-d-d

you redirecting inside sendmail function!

if ($this->email->send($content)) {     $this->redirect('newpassword');          } else {     $this->redirect('userexists'); } 

Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -