3

index.php

$typesql = $_GET['type']

fetch_pages.php

$results = $mysqli->prepare("SELECT name, type FROM artists WHERE type = ?);

$results->bind_param("s", $typesql);
$results->execute();
$results->bind_result($name, $type);

I use the above to get the artist type in index.php, I want to pass it to use it in fetch.php and bind it to my sql query.

1

3 Answers 3

2

You can put the $_GET value to a session and you can use that session variable to access the data on another page

example
page 1

session_start();
$_SESSION['type']=$_GET['type'];

page 2

session_start();
$type = $_SESSION['type'];
Sign up to request clarification or add additional context in comments.

Comments

2

Data can be passed to the next page in various ways. You can pass variable to next page by following ways

  1. Session
  2. Cookie
  3. Url Variable

But in your case using session is the right way.

index.php

session_start(); 
$typesql = $_GET["type"];
$_SESSION["typesql"] = $typesql; 

fetch_pages.php

session_start();
$typesql = $_SESSION["typesql"]; 

$results = $mysqli->prepare("SELECT name, type FROM artists WHERE type = ?);

$results->bind_param("s", $typesql);
$results->execute();
$results->bind_result($name, $type);

Comments

0

You can pass any params through url query(but the length of url is limited).

In index.php

<a href="/fetch_pages.php?type=<?=$typesql?>">fetch pages</a>

In fetch pages.php

// get type from url
$typesql = $_GET['type'];
// and then bind it to sql.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.