Supprimer une ligne dans BDD

pleboys Messages postés 2 Date d'inscription mercredi 14 avril 2010 Statut Membre Dernière intervention 15 avril 2010 - 15 avril 2010 à 20:10
 Derve - 10 avril 2019 à 15:06
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>

PLANNING VARENNE semaine du
au



AJOUTER UN GROUPE

<form action="ajout.php" method="post">
<label for="Groupe">Groupe</label>
:

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>

</form>,
DERNIERS GROUPES AJOUTES

<?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 ' -' . '('. htmlspecialchars($donnees['id']) .') '. htmlspecialchars($donnees['Groupe']) . ' - ' . htmlspecialchars($donnees['Activite']). ' '.htmlspecialchars($donnees['Semaine']) .'

';

}

$reponse->closeCursor();

?>
,
INFOS IMPORTANTES :

<form action="ajout_info.php" method="post">

<label for="infos"></label>

<?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 ' -' . htmlspecialchars($donnees['commentaire']) .'

';
}
$reponse->closeCursor();

?>

</form>

OPTI 1,
OPTI 2,
CATA 1,
CATA 2,
CATA 3,
PAV,
KAYAK POLO,
KAYAK RIVIERE,
CANOE,
ESCALADE,
VTT,
VTT RANDO,
TIR A L'ARC

(am),
TIR A L'ARC

(pm),
ORIENTATION,
CIRQUE,
PECHE,
EQUITATION,

----

Lundi,

<?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'] .')' . '
';

;

}

$reponse->closeCursor();

?>
,

<?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'] .')' . '
';

;

}

$reponse->closeCursor();

?>
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,

----

<?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'] .')' . '
';

;

}

$reponse->closeCursor();

?>
,

<?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'] .')' . '
';

;

}

$reponse->closeCursor();

?>
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,

----

<?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'] .')' . '
';
}

$reponse->closeCursor();

?>
,

<?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'] .')' . '
';

;

}

$reponse->closeCursor();

?>







<form action="supp.php" method="POST">
<label for="supp">
supp</label>:


</form>




</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>


<?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é.';

}
?>

</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.
A voir également:

3 réponses

roymatthieu Messages postés 112 Date d'inscription jeudi 31 août 2006 Statut Membre Dernière intervention 3 février 2011 1
15 avril 2010 à 22:10
parse error = erreur de syntaxe...

en considérant que c'est la ligne de ta requête, la numéro 22 du fichier supp.php

essaye ceci

remplace

{ (mysql_query("DELETE FROM 'planning' WHERE id= '".$_POST['id'].)){


}

par

$query "DELETE FROM 'planning' WHERE id '".$_POST['id']."'";

if(mysql_query($query))

echo 'le groupe '.$_POST['id'].' est supprimé.';

ca risque de pas fonctionner car tu dois choisir... soit tu travailles avec PDO soit avec MYSQL_QUERY...

choisis pdo...

Vas faire un tour sur le site du zéro ils ont des tutos facile à comprendre et qui progresse pas à pas...
1
Rejoignez-nous