How to pass a variable to another page
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 am using 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.
+3
source to share
3 answers
Data can be transferred to the next page in various ways. You can pass a variable to the next page in the following ways.
- Session
- Cookie
- Url variable
But in your case, using session is the right way to go.
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);
+2
source to share