-1

I support a database how can I share a variable from one page to another?

My page choose.php when it is loaded generates buttons with a field value of a database table as value. I have to make sure that at the click of the button: - save me a table data ("id") - I am redirected to another page - on the page where I am redirected to get the variable and put it in a query

it's possible? If so how?

<!DOCTYPE html>
<?php 
 session_start();
    if(!isset($_SESSION["username"])){
     header('location: ../index.php');
    }else
    {
    
?>
<?php
$servername = "localhost";
$username = "";
$password = "";
$dbname = "";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "SELECT idCantiere,nomeCantiere,codiceCommessa,indirizzoCantiere FROM Cantiere";
$result = $conn->query($sql);
echo'<h1> <font face="verdana" color="green">Quale Cantiere desideri Modificare?</font> </h1>';
if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
  
  echo'<br><br><br>';
  echo'<a href="#" class="myButton" alt="">' . $row["nomeCantiere"] . '</a>';
      
  
  
    }
 echo'<br><br><br>';
 echo '<a href="../pagineHtml/inserimento/inserimentoGenerale/inserimentoCantiere.php" class="myButton" alt="Nuovo Cantiere +">Nuovo Cantiere +</a>';
 
} else {
    echo "0 results";
}
$idCantierePerSelect = $_POST["idCantiere"];
global = $idCantierePerSelect;

echo $idCantierePerSelect;



$conn->close();
?>

For now I only managed to do the automatic loading of the buttons ... and I thought of putting "idCantiere", which is the field that I have to go from table to table, global

NarcosZTK_10
  • 137
  • 3
  • 11
  • 1
    Possible duplicate of [PHP Pass variable to next page](https://stackoverflow.com/questions/871858/php-pass-variable-to-next-page) – JeuneApprenti Oct 01 '18 at 09:47

1 Answers1

0

One way of passing variables between pages is 'posting' it in the URL.

This question has been answered before, look here.

Passing multiple variables to another page in url

In short add:

<a href="index.php?idCantiere=".$idCantiere.""></a>

Then at index.php do

$idCantiere = $_GET['idCantiere']
Tycho
  • 48
  • 5