Home » Php » forms – transfer variable betweet two php page

forms – transfer variable betweet two php page

Posted by: admin February 25, 2020 Leave a comment

Questions:

i have 3 page the first is html where i use then i send the data to the second page (php) with post where i have some condition, then i will send the data again for the third php page where i will put it in table (html)
my probleme is the data don’t send to the third php page

the 2nd page

if(isset($_POST['matier']) and isset($_POST['semaine']))
{
    $matier = $_POST['matier'] ;
    $semain = $_POST['semaine'] ;

    header('Location:EmploiMetierSemaine.php?'.$matier.' & '.$semaine);
}

the third page

<?php

                $matier = $_GET['m'] ;
                $semaine = $_GET['s'] ;
?>

any help please

How to&Answers:

You are not passing the params as parameters again but only values here:

header('Location:EmploiMetierSemaine.php?'.$matier.' & '.$semaine);

If you want to pass them as m and s you have to tell your location header so:

header('Location:EmploiMetierSemaine.php?m='.$matier.'&s='.$semaine);

Note that I also removed the spaces around the & since they don’t make any sense in the URL.

Answer:

in second page url should be like this EmploiMetierSemaine.php?m=matier&s=semaine

if(isset($_POST['matier']) and isset($_POST['semaine']))
{
    $matier = $_POST['matier'] ;
    $semaine = $_POST['semaine'] ;

    header('Location:EmploiMetierSemaine.php?m='.$matier.'&s='.$semaine);
}

Answer:

Nowdays If in same case you need to pass a values to multiple pages consecutive with redirection, maybe it’s better to review and redesign your program. in other word it’s like you are doing something in wrong way.

However, your 2th page must be somthing like this:

$matier = $_POST['matier'] ?? NUll;
$semain = $_POST['semaine'] ?? NUll;

header('Location:EmploiMetierSemaine.php?m='.$matier.'&s'.$semaine);

And use $_GET on 3th page.