3

I am working on a custom module where i enter values and if it matches in db it redirects to home page with a message that displays on home page as blah Blah ,or if not goes to login page. I tried the below public function with the condition as

if(count($alldata)==1) {
Mage::getSingleton('helloworld/helloworld')->addSuccess('my message goes here');

$this->_redirect('home');


 }else {
$this->_redirect('customer/account');
  }

but this gives a precces request error.

enter image description here

this is my whole code i added in my controller

 public function loginnAction()
  {
  if($this->getRequest()->getParams()) {
  $param = $this->getRequest()->getParams();


      $username = $param['fname'];
      $mobile = $param['mobileno'];


$connectionresource = Mage::getSingleton('core/resource'); 
$readconnection = $connectionresource->getConnection('core_read'); 

$table = $connectionresource->getTableName('helloworld/helloworld'); 
$allrecord = $readconnection->select()->from(array('helloworld'=>$table))->where('helloworld.mobileno=?', $mobile) 
->where('helloworld.firstname=?', $username); 
$alldata =$readconnection->fetchAll($allrecord);
 if(count($alldata)==1) {
Mage::getSingleton('helloworld/helloworld')->addSuccess('my message goes here');

$this->_redirect('home');


 }else {
$this->_redirect('customer/account');
  }

  }
  }

Is it not the correct format ?Or is there more i should do change?

Updated code

public function loginnAction()
  {
  if($this->getRequest()->getParams()) {
  $param = $this->getRequest()->getParams();


      $username = $param['fname'];
      $mobile = $param['mobileno'];


$connectionresource = Mage::getSingleton('core/resource'); 
$readconnection = $connectionresource->getConnection('core_read'); 

$table = $connectionresource->getTableName('helloworld/helloworld'); 
$allrecord = $readconnection->select()->from(array('helloworld'=>$table))->where('helloworld.mobileno=?', $mobile) 
->where('helloworld.firstname=?', $username); 
$alldata =$readconnection->fetchAll($allrecord);
if(count($alldata)==1) {
Mage::getSingleton('core/session')->addSuccess('my message goes here');

$this->_redirect('home');


 }else {
$this->_redirect('customer/account');
  }

  }
  }

1 Answer 1

7

Use the Magento global messaging system:

success

Mage::getSingleton('core/session')->addSuccess('my message goes here');

error

Mage::getSingleton('core/session')->addError('my message goes here');

warning

Mage::getSingleton('adminhtml/session')->addWarning('my message goes here');

The message will be displayed in the next rendered page, if your template supports it.

Redirect or reload the user to show the message.

4

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.