Supprimer une ligne d'un tableau avec bdd

Résolu/Fermé
Flo313Z Messages postés 119 Date d'inscription jeudi 14 février 2013 Statut Membre Dernière intervention 16 avril 2018 - 21 avril 2013 à 23:36
 loupix - 22 avril 2013 à 13:36
Bonsoir à tous,
Voilà j'ai un petit souci. ma page web génère un tableau via ma base de données.je voudrai créer un bouton a coté de chaque ligne qui me permettrai de supprimé la ligne visé (par rapport a ID de ma bdd) j'ai essaye de faire celà avec un formulaire mais je arrive pas a récupérer ID sur ma page de traitement.
voici mon code :
tableau.php
<?php
$taille=25;
try
{
	$bdd = new PDO('mysql:host=localhost;dbname=test1','root','');
}
catch(Exception $e)
{
	die('Erreur : '.$e->getMessage());
}
$reponse = $bdd->query('SELECT * FROM video ORDER BY id');
	echo '<table border="1" class="tableau">';
	echo '<thead>';
	echo '<tr>';
	echo '<th>Titre</th><th>Annee</th><th>Note</th><th colspan="2">Options</th>';
    echo '</tr>';
	echo '</thead>';
	
	echo '<tfoot>';
	echo '<tr>';
	echo '<th colspan="5"><a href="./formulaire_insertion_video.php">Ajouter</a></th>';
	echo '</tr>';
	echo '</tfoot>';
	
while ($donnees = $reponse->fetch())
{
	echo '<tr>';
	// echo '<td>'.$donnees['id'].'</td>';
	echo '<td>'.$donnees['titre'].'</td>';
	if ($donnees['annee'] != 0)
	{
		echo '<td>'.$donnees['annee'].'</td>';
	}
	else
	{
		echo '<td>????</td>';
	}
	if (isset($donnees['note']) or $donnees['note'] == 0)
	{
		echo '<td>';
		for($i = 1; $i <=$donnees['note']; $i++)
		{
			echo '<img src="icons/etoile_jaune.png" width="'.$taille.'" height="'.$taille.'" alt="etoile_jaune"/>';
		}
		for($i = $donnees['note'];$i < 5; $i++)
		{
			echo '<img src="icons/etoile_grise.png" width="'.$taille.'" height="'.$taille.'" alt="etoile_grise"/>';
		}
		echo '</td>';
	}
	else
	{
		echo '<td>';
		for($i = 1; $i <=5; $i++)
		{
			echo '<img src="icons/etoile_grise.png" width="'.$taille.'" height="'.$taille.'" alt="etoile_grise"/>';
		}
		echo '</td>';
	}
	echo '<form action="./video/formulaire_modification_video.php" method="GET">';
	echo '<td><input type="hidden" name="id" value="'.$donnees['id'].'"/><input type="image" src="icons/Modifier.png" width="'.$taille.'" height="'.$taille.'" Value="submit"/></td>';
	echo '</form>';
	echo '<form action="./video/formulaire_suppression_video.php" method="POST">';
	echo '<td><a href="./formulaire_suppression_video.php"><img src="icons/Supprimer.png" width="'.$taille.'" height="'.$taille.'" alt="Supprimer"/></a></td>';
	echo '</tr>';
	echo '</form>';

}
$reponse->closeCursor();
	echo '</table>';
?>

page de traitement
formulaire_modification_video.php
<?php
$_POST['id'] = $id;
echo $id;
?>

quand j'utilise la method=GET je vois bien ID dans URL mais elle ne s'affiche pas dans mon
echo $id; de ma page de traitement

toute aide et la bienvenu !!
A voir également:

1 réponse

ton code me parait pas mal, mais j'ai un doute sur ton formulaire ;
je ne voit pas de boutton submit

au pire, si tu veut "envoyer" ton formulaire en cliquant sur l'image en rajoutant :
onclick="this.parentNode.submit();"

Bref, sinon ton code php marcheré mieux comme ça :

<?php
$id = $_GET['id']
echo $id;
?>
0
Flo313Z Messages postés 119 Date d'inscription jeudi 14 février 2013 Statut Membre Dernière intervention 16 avril 2018 6
22 avril 2013 à 12:23
salut,
le bonton submit et juste a coté la balise hidden
echo '<td><input type="hidden" name="id" value="'.$donnees['id'].'"/><input type="image" src="icons/Modifier.png" width="'.$taille.'" height="'.$taille.'" Value="submit"/></td>';

j'ai essayé de le remplacer par onclick mais j'ai toujours le même souci "variable undefini"
0
Autant pour moi !

Et pour le code php, ta essayer ?

$id = $_GET['id']; .

au pire, tu peut regarder ou est placer ta variable

print_r($_GET);
print_r($_POST);

ou, au mieux pour bien essayer l'affectation de la variable $id
$id = 123;
$id = $_GET['id']; // ou $_POST['id']
echo $id;
0
Flo313Z Messages postés 119 Date d'inscription jeudi 14 février 2013 Statut Membre Dernière intervention 16 avril 2018 6
22 avril 2013 à 12:54
oui j'ai essayé mon $id vaut 123
c'est comme si id passait pas
0
Flo313Z Messages postés 119 Date d'inscription jeudi 14 février 2013 Statut Membre Dernière intervention 16 avril 2018 6
22 avril 2013 à 13:17
c'est bon ca marche j'ai juste fait une inversion $id = $_post['id]

merci beaucoup loupix !
0
les trucs bête ça m'arrive souvent aussi ;-)

Ravis de t'avoir pus t'aider ; Bonne continuation
0