Jump to content

Passing Array result to another PHP page


_spaz

Recommended Posts

I'm having issues passing an array result thru a form to another PHP page...I've tried a few things and can't figure it out.  I have a series of array results like so:

 

alert[0]= "image 1"

alert[1]= "image 2"

alert[2]= "image 3"

 

I would like to be able to have a user form input box to select say alert[1] by pressing "1" on the main.php page and push that array result to showimage.php.  Not sure if the below is correct in any way shape or form....

 

<form action="showimage.php" method="post">

Enter Alert #: <input type="text" name="arrayresult"/>

<input type="hidden" name="image" value="<?=$alert[$arrayresult];?>"/>

<input type="submit" />

</form>

 

Any help would be great, i've received some great help for other issues already... wish i came to you guys earlier:)

You could try putting it in a session variable.

 

if(isset($_POST['arrayresult'])) {
     $_SESSION['carryover'] = $alert[$arrayresult];
}

 

Then call it on the other page.

 

echo $_SESSION['carryover'];

 

EDIT: I see what you are trying to do, and realised it is a lot more tricky than I thought. Sessions would be one way of carrying over the result, as well as $_POST, but i'm not too sure how to get it to select between the arrays and send it.

define the array on showimage.php and with the post variable arrayresult do the following

echo $alert[$_POST['arrayresult']];

 

if you cant define the array on showimage.php then pass it through the session, or serialize it and pass it through a post variable (though I would just pass it through the session)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.