Supprimer une ligne de table en php

Résolu/Fermé
zeelox Messages postés 119 Date d'inscription samedi 30 mai 2015 Statut Membre Dernière intervention 8 mars 2019 - 14 août 2015 à 19:41
zeelox Messages postés 119 Date d'inscription samedi 30 mai 2015 Statut Membre Dernière intervention 8 mars 2019 - 15 août 2015 à 15:16
voila j'ai un pb :/
je voudrais supprimer un commentaire quand on clic sur supprimer, donc j'ai mit un lien avec GET .. mais j'ai 2 problemes :

1/ quand je suis dans ?title=titre_du_sujet&action=
supprimer

et que j'envoie le commentaire, sa me supprime l'ancien :/
2/ je n'arrives pas a rediriger l'utilisateur a ?title=titre_du_sujet
(sans le action=supprimer)

voila si quelqu'un peut m'aidez je suis preneur ^^ le code :
<?php
ob_start();
session_start();
require('includes/header.php');
require('includes/connected.php');
require('../bdd.php');

$req2 = $bdd->query(" SELECT * FROM sujets ");
$sujetInfos = $req2->fetch();

$req2 = $bdd->prepare(" SELECT * FROM sujets WHERE title = ? ");
$req2->execute(array($_GET['title']));
$sujetInfos = $req2->fetch();

$req = $bdd->prepare(" SELECT * FROM users WHERE ndc = ? ");
$req->execute(array($sujetInfos['autor']));
$autorInfos = $req->fetch();

$req3 = $bdd->query(" SELECT * FROM sujets ");
$usersInf = $req3->fetch();

if($_GET['title'] == $sujetInfos['title'])
{
	if(isset($_POST['sub_comment']))
	{
		$req = $bdd->prepare(" INSERT INTO comments(autor, content, id_sujet) VALUES(?, ?, ?) ");
		$req->execute(array($_SESSION['ndc'], $_POST['comment_content'], $sujetInfos['id']));
	}
?>

<div class="autor">
	<h4><?php echo $sujetInfos['title']; ?></h4>
	<br>
	<p><a href="../profil.php?id=<?php echo $autorInfos['id'] ?>"><?php echo $autorInfos['ndc'] ?></a> - le <?php echo $sujetInfos['date'] ?></p>
</div>

<br><br>

<div class="well well-sm">
  <?php echo $sujetInfos['content'] ?>
</div>

<br>

<a href="<?php echo $sujetInfos['link'] ?>" class="btn btn-primary" target="_blank">lien utile</a>

<?php
	if($_SESSION){
		if($_SESSION['ndc'] == $sujetInfos['autor'])
		{
			echo '<br /><br /><a href="edit.php?title='. $sujetInfos['title'] .'">Modifier</a>';
			echo '<br /><a href="../">Retour</a>';
		}
	}
	
?>

<br><br><br>


<?php
if($_SESSION) /*Si connecté*/
{
?>
<form method="post" action="">
<div class="form-group">
    <label for="comment_content" class="col-lg-2 control-label" style="text-align:right"><?php echo $_SESSION['ndc'] ?></label>
      <div class="col-lg-10">
        <textarea name="comment_content" placeholder="Commentaire..." cols="100" style="background-color: #f9f9f9;border-radius:5px;"></textarea>
      </div>
</div>
<div class="form-group">
    <div class="col-lg-10 col-lg-offset-2">
        <input type="submit" value="Commenter" name="sub_comment" class="btn btn-primary">
        <input type="hidden" value="<?php echo $sujetInfos['id']; ?>" name="id_sujet_comment">
    </div>
</div>
</form>
<?php }else { echo "Vous devez être connecté pour commenter";} ?> <!-- fin  -->
<br><br><br><br><br><br>
<?php

$requete = $bdd->prepare(" SELECT * FROM comments WHERE id_sujet=? ORDER BY id DESC ");
$requete->execute(array($sujetInfos['id']));

while ($commentInf = $requete->fetch()) 
{
	if($_SESSION)
	{
		if($_SESSION['ndc'] == $commentInf['autor'])
		{
		echo '<div class="commented_content"><p style="color: #2196f3;padding-left:10px;padding-top: 5px;display:inline-block">' .$commentInf['autor']. '</p><p style="display:inline-block;margin-left:3px;">le - <font color="#2196f3">'.$commentInf['date'].' </font></p> <br> <p style="padding-left:10px;padding-bottom:25px;"> '.$commentInf['content'].' </p> <a href="sujet.php?title='.$sujetInfos['title'].'&action=supprimer" style="padding-left:10px;">Supprimer</a> </div>';
			if(isset($_GET['action']))
			{
				$requete2 = $bdd->prepare(" SELECT * FROM comments WHERE id_sujet=? ");
				$requete2->execute(array($sujetInfos['id']));
				$commentInf2 = $requete2->fetch();

				$reqSupr = $bdd->prepare(" DELETE FROM comments WHERE id = ? ");
				$reqSupr->execute(array($commentInf2['id']));
			}
		}
	}
	else
	{
	echo '<div class="commented_content"><p style="color: #2196f3;padding-left:10px;padding-top: 5px;display:inline-block">' .$commentInf['autor']. '</p><p style="display:inline-block;margin-left:3px;">le - <font color="#2196f3">'.$commentInf['date'].' </font></p> <br> <p style="padding-left:10px;padding-bottom:25px;"> '.$commentInf['content'].' </p></div>';		
	}
}

?>

<br><br><br>

<?php
require('includes/footer.php');
}
ob_end_flush();
?>



A voir également:

1 réponse

NHenry Messages postés 15113 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 22 avril 2024 331
14 août 2015 à 23:01
Bonsoir,

Pour identifier le message à supprimer, pourquoi ne pas utiliser son Id à la place du titre ?
Idem pour la redirection ?
0
zeelox Messages postés 119 Date d'inscription samedi 30 mai 2015 Statut Membre Dernière intervention 8 mars 2019
15 août 2015 à 15:16
j'avais essayer mais sa ne marchais pas, j'ai réussis tout seul en passant par un boutton et en faisant la meme chose mais avec isset ;) merci
0