CODE PHP

Suivre ce topic
Ce topic est suivi par : alla
alla

alla Le 22 mai 2017 à 14:07 (Édité le 25 janvier 2019 à 17:53)

salut voici mon code PHP c'est le même code que PRIMFX que j'utilise pour créer mon FORUM mais pour afficher les reponse aux topics on me dit qu'il y a une erreur à la ligne que j'ai mit en rouge alors que c'est le même code que j'ai écrit. je comprend rien alors aidez moi svp. je suis un débutant en PHP.

<?php
require('php/config.php'); /* Contient la connexion à la $bdd */
$categories = $bdd->query('SELECT * FROM categorie ORDER BY nom');

?>
<!DOCTYPE html>
<html>
<head>
    <title>FORUM</title>
    <link rel="stylesheet" type="text/css" title="stylecss" href="css/style.css"/>
    <meta charset="utf-8">
</head>
<body >
<?php require('js/header1.php')?>
<div id="bloc_page">
<table id="table">
    <tr>
        <th ><h2>AUTEUR</th></h2>
        <th ><h2>SUJET:<?= $topic['sujet'] ?> </th></h2>
    </tr>
    <tr>
        <td><h2><?= $auteur['pseudo']?></td></h2>
        <td><h2><?= $topic['contenu']?></td></h2>
    </tr>
    <?php while($r = $reponse->fetch()){?>
    <tr>
        <td><h2></td></h2>
        <td><h2><?= $r['contenu']?></td></h2>
    </tr>
    <?php } ?>
</table>
<br />
<form method="POST">
    <textarea placeholder="votre reponse" name="topic_reponse" style="width:80%"></textarea><br />
    <input type="submit" name="topic_reponse_submit" value="Poster votre réponse">
</form>
    <?php if(isset($reponse_msg)) { echo $reponse_msg; }?>  
</div>
<?php require('js/footer.php')?>
<?php require('js/aside.php')?>
</body>
</html>


ET VOICI LE FICHIER PHP


<?php
    session_start();
    require('php/config.php');
        
    if(isset($_GET['titre'],$_GET['id']) AND !empty($_GET['titre']) AND !empty($_GET['id'])){
        
        $get_titre = htmlspecialchars($_GET['titre']);
        $get_id = htmlspecialchars($_GET['id']);
        
    
        
        $titre_original = $bdd->prepare('SELECT sujet FROM topics WHERE id= ?');
        $titre_original->execute(array($get_id));
        $titre_original = $titre_original->fetch();
        $titre_original = $titre_original['sujet'];
        
        
        if($get_titre = urlencode($titre_original)){
            
            $topic = $bdd->prepare('SELECT * FROM topics WHERE id = ?');
            $topic->execute(array($get_id));
            $topic = $topic->fetch();
            
            $auteur = $bdd->prepare('SELECT * FROM membre WHERE id = ?');
            $auteur->execute(array($topic['id_createur']));
            $auteur = $auteur->fetch();
            
            $reponse = $bdd->prepare('SELECT * FROM messages WHERE id_topic = ?');
            $reponse->execute(array($get_id));
    
            
            
        if(isset($_POST['topic_reponse_submit'],$_POST['topic_reponse'])){
        
            $reponse = htmlspecialchars($_POST['topic_reponse']);
            
            if(isset($_SESSION['id'])){
                if(!empty($reponse)){
                    
                    $ins = $bdd->prepare('INSERT INTO messages(id_topic,id_posteur,contenu,date_heure_post) VALUES(?,?,?,NOW())');
                    $ins->execute(array($get_id,$_SESSION['id'],$reponse));
                    
                }else{
                    $reponse_msg = "votre réponse ne doit pas être vide!!!";
                }
            }else{
                header('location: index.php');
            }
            
        }
            
        }else{
            die('erreur: titre invalide');
            
        }
        
    }else{
        die('erreur!!!');
    }
    require('views/topic_view.php');
?>

et voici l'erreur qui s'afffiche:
Fatal error: Call to a member function fetch() on a non-object in C:\wamp\www\projet\views\topic_view.php on line 25
alla

alla Le 22 mai 2017 à 14:10

et voici l'erreur qui s'affiche:

Fatal error: Call to a member function fetch() on a non-object in C:\wamp\www\projet\views\topic_view.php on line 25
alla

alla Le 22 mai 2017 à 15:24

merci a vous j'ai finalement trouver où etait l'erreur!!!!
Profil introuvable

Profil introuvable Le 26 mai 2017 à 21:51

Hello 'alla',

Utilise les balises qui sont mises à ta disposition notamment la balise [CODE], car c'est très désagréable pour nous de voir le code comme cela...
Si ton problème est résolu, met ton topic en "Résolu" et informe aussi la solution pour que d'autres membres ne recrée pas un topic au même sujet.

Amicalement 😉
Vous devez être connecté pour poster une réponse. Se connecter ou Créer un compte