Jump to content

moving from one page to another


designingamy

Recommended Posts

This may be difficult to understand, but I'll try to make it as simple as I can.

 

I have 3 pages.  I need to connect information from page 1 to page 2.  Here's how I do it....

 

food.php?type=fruit&color=red

 

The next page will have in it of course...

 

$type=$_GET['type']
$color=$_GET['color']

$sql="SELECT * FROM food WHERE type=$type AND color=$color";

 

Now my question is that I need to link page 3 to pull the same information from page 1.  Let's say for the page 3 I need to get not only the food type and the food color but the food shape.  The first page told the type and color, but the second page only tells the shape but I need all to be pulled for the 3rd page.  Do I have to do some kind of session to pull that info, or could I just use this for the 2nd page.....

 

allfood.php?type=$type&color=$color&shape=round

 

And then this code on the 3rd page...

 

$type=$_GET['type']
$color=$_GET['color']
$shape=$_GET['shape']

$sql="SELECT * FROM food WHERE type=$type AND color=$color AND shape=$shape";

 

It seems like using GET and using variables could be risky.  I'm not sure if it's even the right thing to do in this case.  Can anyone help?

 

Thanks bunches in advance!

~Amy

 

 

Link to comment
https://forums.phpfreaks.com/topic/110833-moving-from-one-page-to-another/
Share on other sites

It depends,

 

You can use $_GET vars across all the pages, and if it's for a small amount of choices (ie: less than 5, or choices that don't change) you could hardcode it in.  example, $color, will always usually be the simple colors (red,blue,green,yellow..etc,etc.) so you could have a check on your get vars:

<?php
$colorArray = Array("red","blue","green");//etc
if(isset($_GET['color']))
{
  if(in_array($_GET['color'],$colorArray))
  {
    $color = $_GET['color'];
  }else{
    echo 'Not a valid color.';
  }
}
?>

 

You could also send the vars using $_POST and a hidden form or something... but you'd still probably want to validate...

 

If you're worried about the integrity of the values, you could use sessions, and store the vars in the session data.  Afaik, it's hard for clients to change session data.. and if so you could write a check to make sure the values haven't changed.  (make a hash value of the choices from page 1, and if it changes when attempting to check the first hash vs a rehash, then something has changed).

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.