0

I'm trying to send an array with its values from the first page to the second page. On the second page what I want to happen is that it the sent array values will be transferred to a new array. Here's my current progress:

Snippet code of Report_Status.php (First Page / Source, where the array with values is initailized)

$message = array(
            'title' => 'Report Approved!',
            'body' => 'Thank you for reporting! We already approved/verified your report as a legit fire incident. Wait for the firefighters to arrive.'
        );
        while ($User_Row = mysqli_fetch_array($Retrieve_User, MYSQLI_ASSOC)){
            $User_Token[] = $User_Row['User_Token'];
        }
       send_notification($User_Token, $message); //calling a function of the second page. 
//I will replace the it from calling a function to redirecting to a specific web link

This first page retrieves a specific data (which is the user's token) from the database and stores it into an array ($User_Token[]). Initialization.

Snippet code of Push_User_Notification.php (Second page / Destination, where the array with its values will be received.

//Here: there should be the code for catching/receving the array
$Retrieve_Target_Tokens_Query = "SELECT * FROM User WHERE User_Token = $tokens";
$Retrieve_Target_Tokens = mysqli_query($Connection, $Retrieve_Target_Tokens_Query);
$tokens = array();

if(!$Retrieve_Target_Tokens){
    echo "<script type = 'text/javascript'> alert('Server Error: Could retrieve tokens from database because of this error: ". mysqli_error($Connection)."') </script>";
}

if(mysqli_num_rows($Retrieve_Target_Tokens) > 0){
    while($Token = mysqli_fetch_array($Retrieve_Target_Tokens)){
        $tokens[] = $Token['User_Token'];
    }
}
$message = array("message" => "Your Report has been approved by an admin! Please wait for firefighter/s to arrive.");    
send_notification($tokens, $message);

function send_notification ($tokens, $message)
{
//Process of Firebase sending notification here (No problem on this function)
}

Question:

  1. How can i send an array from a one page and receive it successfully to another page?

P.S. This code/s sends a push notification to specific android users only.

2 Answers 2

1

You can use Session variable the link : http://php.net/manual/en/reserved.variables.session.php

or you can pass it with JSON if you want to do it with a call in Javascript.

Hope it was helpful :)

Sign up to request clarification or add additional context in comments.

Comments

0

I would use sessions for this.

Here's a similar question with the answer you need: Pass array from one page to another

Comments

Your Answer

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