Passing Variables between PHP pages then performing a MySQL search

时间:2015-08-07 02:07:02

标签: php mysql

fairly new to PHP and webdesign.... I have a website which has a bunch of products for vehicles - all of this is stored in a database.

In order to narrow down what products are available, I want to take the user through 2-3 pages where they firstly select what categorey of product they want, then what make of car they have, then the model, then I want to run a mysql query with that information and return the answerson a page.

I already have the code to request the info from a database and then display it on the page, but The way the current website is setup, they are hard coded mysql queries (meaning the user didnt input any data to get there).

So how can I transfer variable between php pages? Page 1 (contains Categorey) - then pass to Page 2 (contains Make) then page to Page 3 (contains Model) then compile the three variavles collections, and pass them to results.php (a standard results page which Gets variables and then searches).

I know this might seem basic, but I am really stumped as to how to get it coded.

If someone can give me an a newbie explanation about how to achieve this? Thank you

1 个答案:

答案 0 :(得分:0)

You can pass PHP variables through URLs for example

Your HTML code,

<a href='yourPage.php?yourVariable=someValue'>TEST!</a>

Your PHP code,

if (isset($_GET['yourVariable'])) {
    $yourVariable = $_GET['yourVariable'];
    // Your code here.
}

Now using this you can create what you want with a little bit of tinkering.

Remember

You need to use $_GET because parameters are being passed using the URL and not a POST request.

Don't forget to clean all input.