PROJET-WEB_STRI1A/WEB/voiture/fonctionsVoiture.php

64 lines
2.0 KiB
PHP

<?php
/*require ('../connectionBD.php');
$mail = null;
$db = connexionBD();
init();
*/
$matricule = $_POST['matricule'];
$marque = $_POST['marque'];
$modele = $_POST['modele'];
$nbplaces = $_POST['nbplaces'];
$anneefab = $_POST['anneefab'];
if(isset($_POST['submitadd']))
{
addVoiture($matricule, $marque, $modele, $nbplaces, $anneefab);
}
if(isset($_POST['submitchange']))
{
changeVoiture($matricule, $marque, $modele, $nbplaces, $anneefab);
}
if(isset($_POST['submitshow']))
{
showVoiture();
}
function init(){
session_start();
global $mail;
//Si on est pas connecté redirection vers la page de connexion
if(!isset($_SESSION['mail'])){
header('Location: ../index.php');
exit();
}
else{
$mail = $_SESSION['mail'];
}
}
function addVoiture($matricule, $marque, $modele, $nbplaces, $anneefab){
//global $db;
$requete = "INSERT INTO public.voiture (matricule, marque, modele, nbplaces, anneefab, mail) VALUES ('".$matricule."','".$marque."','".$modele."','".$nbplaces."','".$anneefab."','mail');";
//$requete = "INSERT INTO 'public'.'voiture' ('matricule','marque','modele','nbplaces','anneefab','mail') VALUES ('".$matricule."','".$marque."','".$modele."','".$nbplaces."','".$anneefab."','".$_SESSION['mail']."');";
echo "requete =".$requete;
//pg_query($db, $requete);
}
function changeVoiture($matricule, $marque, $modele, $nbplaces, $anneefab){
//global $db;
$requete = "UPDATE public.voiture SET (matricule, marque, modele, nbplaces, anneefab) = ('".$matricule."','".$marque."','".$modele."','".$nbplaces."','".$anneefab."') WHERE mail = 'mail';";
//$requete = "UPDATE public.voiture SET (matricule, marque, modele, nbplaces, anneefab) = ('".$matricule."','".$marque."','".$modele."','".$nbplaces."','".$anneefab."') WHERE mail = '".$_SESSION['mail']."';";
echo "requete =".$requete;
//pg_query($db, $requete);
}
function showVoiture(){
//global $db;
$requete = "SELECT * FROM voiture WHERE voiture.mail = '".$_SESSION['mail']."';";
echo "requete =".$requete;
//pg_query($db, $requete);
}
?>