Marco Basolu
Marco Basolu

Reputation: 41

Passing a variable from an HTML page to another PHP page

I want to pass some value from an HTML page to another PHP page, to do some action about this value. In my HTML code there's also a piece of PHP, that contain my variable (an array).

I've tried to set the variable "var" with this value, but when I'm going to show "var" with the $_GET, on the other PHP page, doesn't work

`

session_start();
require_once __DIR__ . './db_con_marco.php'; 

if (!isset($_SESSION['userSession'])) {
    $msg ="WARNING";
    header("Location: ../index.php?errorMessage=" . $msg);
    exit;   }


$queryText =  "
        SELECT * 
        FROM account
        WHERE BINARY username = '" . $_SESSION['userSession'] . "' ";

$query = $dbCon->query($queryText);
$userRow = $query->fetch_array();

$uCod = $_POST['codice_dettagli'];

$uCod = $dbCon->real_escape_string($uCod);

$check_cod = $dbCon->query("SELECT codice FROM eventi WHERE codice = '$uCod'");
$count = $check_cod->num_rows;

if($count == 0 ){
    $msg ="Evento non presente nel DB";
    header("Location: account_marco.php?errorMessage=" . $msg); }
?>

SAN SIRO BOOKING

<link rel="stylesheet" href="../css/style.css" type="text/css" media="screen">

</head>

    <div class = "titolo_evento_selezionato">

        <?php

            $queryAlpha =  "
            SELECT NomeEvento, date_format(DataOra, '%d.%m.%y (%H:%i)') 
            FROM eventi
            WHERE BINARY codice = '" .$_POST['codice_dettagli'] . "' ";

            $queryEvento = $dbCon->query($queryAlpha);
            $EventoSelezionato = $queryEvento->fetch_array();


            echo($EventoSelezionato[0]);
            echo
            '<h7> 
                    <br>' . $EventoSelezionato[1] .'
                </h7>';

        ?>

    </div>      





    <form class = "seleziona_posto" method = "post" 
                action = "./acquista_evento_action.php? var = <?= $EventoSelezionato[0]; ?>" >


            <p> Seleziona sulla mappa il settore scelto e premi "Acquista" </p>

            <input class = "input_settore_css" type = "text" placeholder = "Settore posto" name = "input_settore" required >

            <input class = "bottone_settore_css" type = "submit" value = "ACQUISTA" name = "btn_settore">


    </form>



  </body>

`

I need to pass the value "EventoSelezionato[0]" to the page "acquista_evento_action.php"

Upvotes: 0

Views: 84

Answers (1)

John.M
John.M

Reputation: 363

Change this:

action = "./acquista_evento_action.php? var = <?= $EventoSelezionato[0]; ?>" >

to

action = "./acquista_evento_action.php?var=<?php echo $EventoSelezionato[0]; ?>" >

It's probably not necessary to remove the short code but it's my preference, you do however need to remove the spaces.

Upvotes: 2

Related Questions