Bonjour,
voila je me décide enfin à poster après 4 jours de recherches infructueuses sur le net.
Etant un grand débutant dans le php/mysql, je n'arrive pas à supprimer de ligne dans la bdd.
j'ai bien saisi la formule :
DELETE FROM 'planning' WHERE id= '".$_POST['id'].
Mais je n'arrive pas à la faire fonctionner ; je tombe toujours sur cette erreur :
Parse error: parse error in D:\wamp\www\tests\supp.php on line 22
j'ai un tableau avec des noms de centre de loisirs. Devant le nom du groupe, je fais apparaitre l'ID afin que mes collègues puisse supprimer le groupe en saisissant l'id dans la case supprimer (en bas du tableau.
je post mon code de ma page "test.php"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
<title>PLANNING VARENNE</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
<!--
.entete {
font-size: 12px;
text-align: center;
}
.contenu {
font-size: 12px;
text-align: center;
}
.titre_tableau {
color: #F00;
font-size: 14px;
}
-->
</style>
</head>
<body>
<h2>PLANNING VARENNE semaine du
au
</h2>
<table width="1125" height="162" border="1">
<tr>
<td width="516" valign="top"><p class="titre_tableau">AJOUTER UN GROUPE</p>
<form action="ajout.php" method="post">
<label for="Groupe">Groupe</label>
:
<input type="text" name="Groupe" id="Groupe" />
<p>Jour :
<label for="jour"></label>
<select name="Jour" id="Jour">
<option>Lundi</option>
<option>Mardi</option>
<option>Mercredi</option>
<option>Jeudi</option>
<option>Vendredi</option>
<option>Samedi</option>
<option>Dimanche</option>
</select>
Activité :
<label for="activite"></label>
<select name="Activite" id="Activite">
<option>Opti 1</option>
<option>Opti 2</option>
<option>Cata 1</option>
<option>Cata 2</option>
<option>Cata 3</option>
<option>Pav</option>
<option>Kayak polo</option>
<option>Kayak rivière</option>
<option>Canoe</option>
<option>Escalade</option>
<option>Vtt</option>
<option>Vtt rando</option>
<option>Tir à l'arc (am)</option>
<option>Tir à l'arc (pm)</option>
<option>Orientation</option>
<option>Cirque</option>
<option>Peche</option>
<option>Equitation</option>
</select>
Créneau :
<label for="creneaux"></label>
<select name="Creneaux" id="Creneaux">
<option>10h00-12h00</option>
<option>14h00-16h00</option>
<option>16h15-18h15</option>
</select>
</p>
<p>
<input type="submit" value="Ajouter" />
</p>
</form>
<p></p></td>
<td width="230" valign="top"><p class="titre_tableau">DERNIERS GROUPES AJOUTES<span class="contenu"></span></p>
<p>
<span class="contenu">
<?php
// Connexion à la base de données
try
{
$bdd = new PDO('mysql:host=localhost;dbname=vpa', 'root', '');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$reponse = $bdd->query('SELECT Groupe, Activite, id, Semaine FROM planning ORDER BY ID DESC LIMIT 0,3');
while ($donnees = $reponse->fetch())
{
echo '<p><strong> -' . '('. htmlspecialchars($donnees['id']) .') '. htmlspecialchars($donnees['Groupe']) . '</strong> - ' . htmlspecialchars($donnees['Activite']). ' '.htmlspecialchars($donnees['Semaine']) .'</p>';
}
$reponse->closeCursor();
?>
</span></p></td>
<td width="318" valign="top" class="titre_tableau"><p> INFOS IMPORTANTES :</p>
<form action="ajout_info.php" method="post">
<p>
<label for="infos"></label>
<input name="infos" type="text" id="infos" value="Entrer toutes infos importantes" size="50" />
<input type="submit" value="Ajouter" />
</p>
<p class="contenu">
<?php
// Connexion à la base de données
try
{
$bdd = new PDO('mysql:host=localhost;dbname=vpa', 'root', '');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$reponse = $bdd->query('SELECT commentaire FROM infos ORDER BY ID DESC LIMIT 0,3');
while ($donnees = $reponse->fetch())
{
echo '<p class="contenu"> -' . htmlspecialchars($donnees['commentaire']) .'</p>';
}
$reponse->closeCursor();
?>
</p>
</form>
<p class="contenu"> </p></td>
</tr>
</table>
<table width="1206" height="126" border="1">
<tr class="entete">
<td width="48"> </td>
<td width="54" class="entete">OPTI 1</td>
<td width="54" class="entete">OPTI 2</td>
<td width="55" class="entete">CATA 1</td>
<td width="55" class="entete">CATA 2</td>
<td width="55" class="entete">CATA 3</td>
<td width="53" class="entete">PAV</td>
<td width="56" class="entete">KAYAK POLO</td>
<td width="56" class="entete">KAYAK RIVIERE</td>
<td width="56" class="entete">CANOE</td>
<td width="62" class="entete">ESCALADE</td>
<td width="53" class="entete">VTT</td>
<td width="56" class="entete">VTT RANDO</td>
<td width="54" class="entete"><p>TIR A L'ARC</p>
<p>(am)</p></td>
<td width="54" class="entete"><p>TIR A L'ARC</p>
<p>(pm)</p></td>
<td width="84" class="entete">ORIENTATION</td>
<td width="56" class="entete">CIRQUE</td>
<td width="55" class="entete">PECHE</td>
<td width="72" class="entete">EQUITATION</td>
</tr>
<tr>
<td rowspan="3" class="contenu">Lundi</td>
<td width="54"><span class="contenu">
<?php
try
{
$bdd = new PDO('mysql:host=localhost;dbname=vpa', 'root', '');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$reponse = $bdd->query('SELECT Groupe, id, Jour, Activite FROM planning WHERE Jour=\'Lundi\' AND Creneaux=\'10h00-12h00\'AND Activite=\'opti 1\'');
while ($donnees = $reponse->fetch())
{
echo $donnees['Groupe'] . ' (' .$donnees['id'] .')' . '<br />';
;
}
$reponse->closeCursor();
?>
</span></td>
<td width="54"><span class="contenu">
<?php
try
{
$bdd = new PDO('mysql:host=localhost;dbname=vpa', 'root', '');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$reponse = $bdd->query('SELECT Groupe, id, Jour, Activite FROM planning WHERE Jour=\'Lundi\' AND Creneaux=\'10h00-12h00\'AND Activite=\'opti 2\'');
while ($donnees = $reponse->fetch())
{
echo $donnees['Groupe'] . ' (' .$donnees['id'] .')' . '<br />';
;
}
$reponse->closeCursor();
?>
</span></td>
<td width="55"> </td>
<td width="55"> </td>
<td width="55"> </td>
<td width="53"> </td>
<td width="56"> </td>
<td width="56"> </td>
<td width="56"> </td>
<td width="62"> </td>
<td width="53"> </td>
<td width="56"> </td>
<td width="54"> </td>
<td width="54"> </td>
<td width="84"> </td>
<td width="56"> </td>
<td width="55"> </td>
<td width="72"> </td>
</tr>
<tr>
<td width="54"><span class="contenu">
<?php
try
{
$bdd = new PDO('mysql:host=localhost;dbname=vpa', 'root', '');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$reponse = $bdd->query('SELECT Groupe, id, Jour, Activite FROM planning WHERE Jour=\'Lundi\' AND Creneaux=\'14h00-16h00\'AND Activite=\'opti 1\'');
while ($donnees = $reponse->fetch())
{
echo $donnees['Groupe'] . ' (' .$donnees['id'] .')' . '<br />';
;
}
$reponse->closeCursor();
?>
</span></td>
<td width="54"><span class="contenu">
<?php
try
{
$bdd = new PDO('mysql:host=localhost;dbname=vpa', 'root', '');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$reponse = $bdd->query('SELECT Groupe, id, Jour, Activite FROM planning WHERE Jour=\'Lundi\' AND Creneaux=\'14h00-16h00\'AND Activite=\'opti 2\'');
while ($donnees = $reponse->fetch())
{
echo $donnees['Groupe'] . ' (' .$donnees['id'] .')' . '<br />';
;
}
$reponse->closeCursor();
?>
</span></td>
<td width="55"> </td>
<td width="55"> </td>
<td width="55"> </td>
<td width="53"> </td>
<td width="56"> </td>
<td width="56"> </td>
<td width="56"> </td>
<td width="62"> </td>
<td width="53"> </td>
<td width="56"> </td>
<td width="54"> </td>
<td width="54"> </td>
<td width="84"> </td>
<td width="56"> </td>
<td width="55"> </td>
<td width="72"> </td>
</tr>
<tr>
<td width="54"><span class="contenu">
<?php
try
{
$bdd = new PDO('mysql:host=localhost;dbname=vpa', 'root', '');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$reponse = $bdd->query('SELECT Groupe, id, Jour, Activite FROM planning WHERE Jour=\'Lundi\' AND Creneaux=\'16h15-18h15\'AND Activite=\'opti 1\'');
while ($donnees = $reponse->fetch())
{
echo $donnees['Groupe'] . ' (' .$donnees['id'] .')' . '<br />';
}
$reponse->closeCursor();
?>
</span></td>
<td width="54"><span class="contenu">
<?php
try
{
$bdd = new PDO('mysql:host=localhost;dbname=vpa', 'root', '');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$reponse = $bdd->query('SELECT Groupe, id, Jour, Activite FROM planning WHERE Jour=\'Lundi\' AND Creneaux=\'16h15-18h15\'AND Activite=\'opti 2\'');
while ($donnees = $reponse->fetch())
{
echo $donnees['Groupe'] . ' (' .$donnees['id'] .')' . '<br />';
;
}
$reponse->closeCursor();
?>
</span></td>
<td width="55"> </td>
<td width="55"> </td>
<td width="55"> </td>
<td width="53"> </td>
<td width="56"> </td>
<td width="56"> </td>
<td width="56"> </td>
<td width="62"> </td>
<td width="53"> </td>
<td width="56"> </td>
<td width="54"> </td>
<td width="54"> </td>
<td width="84"> </td>
<td width="56"> </td>
<td width="55"> </td>
<td width="72"> </td>
</tr>
</table>
<p> </p>
<form action="supp.php" method="POST">
<label for="supp">
supp</label>:
<input type="text" name="num" id="id" />
<input type="submit" value="supprimer" />
</form>
</body>
</html>
code de la page supp.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
<title>supp</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<?php
// Connexion à la base de données
try
{
$bdd = new PDO('mysql:host=localhost;dbname=vpa', 'root', '');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
//Supression d'un enregistrement dans la table 'planning' ou l'id sera égale à la valeur entrée dans la case :
{ (mysql_query("DELETE FROM 'planning' WHERE id= '".$_POST['id'].)){
echo 'le groupe ['id'] est supprimé.';
}
?>
</body>
</html>
je me permet de poster dans le sens ou vous allez mettre 4 min pour résoudre mon problème alors que cela fait 4 jours que je cherche.
vous remerciant par avance.