Insertion de donnee a la base de donnée
mili12loli1
Messages postés
15
Statut
Membre
-
jordane45 Messages postés 30427 Date d'inscription Statut Modérateur Dernière intervention -
jordane45 Messages postés 30427 Date d'inscription Statut Modérateur Dernière intervention -
bonjour,
j'ai besoin d'aide dans ce code
voila reserver.php
et voila la reserv.php
sachant que j'ai 3 tables client , vol , reservation-vol
j veut en cliquant sur le bouton reserver les id de client et vol entre dans la table reservation
j'ai besoin d'aide dans ce code
voila reserver.php
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?[/php/phpintro.php3 php]
include 'entete-acceuil.php';?>
<div id="contenu">
<table width=500 height=500 style="text-align: center;margin: auto;">
<form method="POST" action="reserv.php" >
<caption><h2>confirmation de la réservation</h2></caption><br><br>
<tr><th>
<b>Nom :</b><br>
<input type="text" name="nom" id="nom" style="text-align: center; font-style: bold; width:200px; height:30px;" required="" minlength="3" />
</th>
<th>
<b>Prenom :</b><br>
<input type="text" name="prenom" id="prenom" style="text-align: center; font-style: bold; width:200px; height:30px;" required="" minlength="3"/></th></tr>
<th>
<b>Telephone :</b><br>
<input type="text" name="tel" id="tel" style="text-align: center; font-style: bold; width:200px; height:30px;" required="" minlength="3"/></th>
<th>
<b>Email :</b><br>
<input type="text" name="email" id="email" style="text-align: center; font-style: bold; width:200px; height:30px;" required="" minlength="3" />
</th> </tr>
<tr><th>
<input type="radio" name="allerRetour" value="true" checked="" onclick="showReturn()" style="text-align: center;"/>
Aller Retour </th>
<script type="text/javascript">
function hideReturn() {
document.getElementById("returnDate").style.visibility = 'hidden';
}
</script>
<th>
<input type="radio" name="allerRetour" value="false" onclick= "hideReturn()" style="text-align: center; "/>
Aller simple</th></tr>
<script type="text/javascript">
function showReturn() {
document.getElementById("returnDate").style.visibility = 'visible';
}
</script>
<tr><th>
<b>Ville de départ :</b><br>
<input type="text" name="depart" id="depart" style="text-align: center; font-style: bold; width:200px; height:30px;" required="" minlength="3" />
</th>
<th>
<b>Ville d'arrivée :</b><br>
<input type="text" name="arrivee" id="arrivee" style="text-align: center; font-style: bold; width:200px; height:30px;" required="" minlength="3"/></th></tr>
<tr><th>
<b>Départ le :</b><br>
<input type="date" id="date1" name="date1" style="text-align: center; font-style: bold; width:200px; height:30px;" required="" /> </th>
<th>
<div id="returnDate">
<b>Retour le :</b><br>
<input type="date" id="date2" name="date2" style="text-align: center; font-style: bold; width:200px; height:30px;" required="" />
</div></th>
</tr>
<tr><td></td>
<td><input type="submit" name="reserver" id="reserver" value="reserver"></td>
</tr>
</table>
</form>
</div>
<?php
include 'pied-de-page.php';
?>
</body>
</html>
et voila la reserv.php
<?php
include 'connexion.php';
if (isset($_POST['reserver']))
{if(($_POST['nom']!='')&&($_POST['prenom']!=''))
$nom = $_POST['nom'];
$prenom = $_POST['prenom'];
$tel = $_POST['tel'];
$email = $_POST['email'];
$depart = $_POST['depart'];
$arrivee = $_POST['arrivee'];
$date1 = $_POST['date1'];
$date2 = $_POST['date2'];
$idclt = $connexion->exec('SELECT `id-clt` FROM client WHERE `nom-clt` LIKE ? AND `prenom-clt` LIKE ? AND `tel-clt` LIKE ? AND `email` LIKE ?');
$idclt->execute(array('%'. $_POST["nom"] .'%' , '%'. $_POST["prenom"] .'%','%'. $_POST["tel"] .'%' ,'%'. $_POST["email"] .'%' ));
$idvol = $connexion->exec('SELECT `id-vol` FROM vols WHERE aerop_depar_vol LIKE ? AND aerop_arriv_vol LIKE ? AND dat_dep_vol LIKE ? AND dat_ret_vol LIKE ?');
$idvol->execute(array('%'. $_POST["depart"] .'%' , '%'. $_POST["arrivee"] .'%','%'. $_POST["date1"] .'%' ,'%'. $_POST["date2"] .'%' ));
$query =$connexion->prepare('INSERT INTO `agence de voyage`.`reservation-vol`(`code-resrv-vol`,`id-vol`,`id-clt`,`dat-res`) VALUES(\'\',:idvol,:idclt,:date1)');
$query->bindValue(':idvol', $idvol, PDO::PARAM_INT);
$query->bindValue(':idclt', $idclt, PDO::PARAM_INT);
$query->bindValue(':date1', $date1, PDO::PARAM_INT);
$query->execute();
/*$_SESSION[`id-vol`] = $connexion->lastInsertId();
$_SESSION[`id-clt`] = $connexion->lastInsertId();*/
$_SESSION[`code-resrv-vol`] = $connexion->lastInsertId();
$query->CloseCursor();
header('Location:../client/espace-client.html');
}
?>
sachant que j'ai 3 tables client , vol , reservation-vol
j veut en cliquant sur le bouton reserver les id de client et vol entre dans la table reservation
1 réponse
-
Bonjour,
Déjà.. il semble que tu utilises le PDO ....
il faut donc un ->prepare puis un ->execute
Toi tu n'as que des execute...
Je t'invite fortement à appliquer ceci :
https://forums.commentcamarche.net/forum/affich-37584941-php-pdo-gerer-les-erreurs
Puis également cela :
https://forums.commentcamarche.net/forum/affich-37584947-php-gestion-des-erreurs-debogage-et-ecriture-du-code
On verra ensuite si tu as encore besoin de nous une fois que tu auras corrigé ton code...