utilisation d'une variable global
Bonjour
Je récupère une variable $_POST["name"] depuis un formulaire
je voudrais pouvoir utilisé cette variable dans trois fonctions seulement quand je sort de la première évidement elle est détruite
si je la mets avant la fonction pour quelle soit disponible pour toutes les fonctions j'ai une erreur au lancement du programme !
AU SECOURS Comment je me sort de lâ ?
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
| voici mon fichier de fonction
<?php
function insertform(){
if(isset($_POST["name"])){
$host = 'localhost';
$dbname = 'mabase';
$username = 'root';
$password = '';
$mail = $_POST['mail'];
$name = $_POST['name'];
$pdo = new PDO("mysql:host=$host;dbname=$dbname","$username","$password");
$sql = "INSERT INTO `reservation` (`nom`, `mail`) VALUES ('$name', '$mail')";
$resultat = $pdo->exec($sql);
if(!$resultat) {
echo "Échec de l'opération d'insertion";
}
}
}
function yourchoicecity(){
$servername = 'localhost';
$username = 'root';
$password = '';
$dbase = 'mabase';
if(isset($_POST["choicecity"])){
try {
$pdo = new PDO("mysql:host=$servername;dbname=$dbase","$username","$password");
$choicecity = $_POST["choicecity"];
$today = date("Y-m-d");
$city = "UPDATE reservation SET choicecity='$choicecity' WHERE nom='$name'";
$resultcity = $pdo->exec($city);
}
catch (PDOException $exc) {
echo $exc->getMessage();
exit;
}
if($resultcity !== false){
?>
<script>
document.location.replace("index.php" );//retour à la page d'accueil//
</script>
<?php
}
}
}
function yourchoicedate(){
$servername = 'localhost';
$username = 'root';
$password = '';
$dbase = 'mabase';
if(isset($_POST["choicedate"])){
try {
$pdo = new PDO("mysql:host=$servername;dbname=$dbase","$username","$password");
$datedebut = $_POST["datedebut"];
$datefin =$_POST['datefin'];
$today = date("Y-m-d");
$date = "UPDATE reservation SET creation='$today', debut='$datedebut', fin='$datefin' WHERE nom= '$name'";
$resultdate = $pdo->exec($date);
}
catch (PDOException $exc) {
echo $exc->getMessage();
exit;
}
}
}
?> |