Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm using PHP, Smarty, MySQL for my website. I have an array of error messages and I want to use this array in a PHP file to which I'm redirecting the control. However, I'm not understanding how should I achieve this.

code is as follows:

$error_msg  = $contact_us->GetAllErrors();
$smarty->assign('error_msg', $error_msg);
$return_url = "view_contact_us.php?page=".$_SESSION['contact_us']."&from_date={$from_date}&to_date={$to_date}&contact_full_name={$contact_full_name}&contact_label={$hidden_contact_label}&error_msg=".$error_msg;
header("Location:".$return_url);

I tried many different ways, but I'm not able to use the array $error_msg in the file view_contact_us.php.

If I print the array $error_msg it looks like following:

   Array
(
    [error_msgs] => Please select at least one enquiry
Please select at least one enquiry label
)
share|improve this question
    
see here: stackoverflow.com/questions/1763508/… –  Awlad Liton Jan 10 at 6:38

1 Answer 1

You can use $_SESSION variable and put or assign your array() as its value.

For example:

$arr = array();

$arr[0] = "error_1";
$arr[1] = "error_2";
$arr[2] = "error_3";

$_SESSION['errorMsg'] = $arr;

After that, $_SESSION['errorMsg'] can now be use globally throughout all webpages.

share|improve this answer
    
Thanks for your answer but can you suggest me another way which would not make use of session variables? –  PHPLover Jan 10 at 6:45
    
In that case, please see Awlad Liton's comment on your question, i think it relates more to your issue. –  Kiel Labuca Jan 10 at 6:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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