Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 2 of 2
  1. #1
    Junior Member
    Join Date
    Jul 2018
    Posts
    3
    Member #
    59668

    how to get a php forum working?

    hey guys!

    I have been trying to follow this tutorial and just trying to get all the features working. This person has left some unfinished features such as adding how many replies the user has posted and I thought it would be as easy as pulling the $row of the user that has posted and counting it from there but it just add the count only once.... Here is the code and I hope that i have formatted it correctly: I can't get the update topics, topic_reply to work effectively...

    PHP Code:

    <?php
    include_once 'header.php';
    if (!isset(
    $_SESSION['u_uid'])) {
        
    header ("Location: index.php?post_reply_parse=notlogin");
        exit();
        } else {
        if (!isset(
    $_POST['reply_submit'])) {
            
    header("Location: post_reply.php?post_reply_parse=error");
            exit();

        } else {
            include_once 
    'includes/dbh.php';
            
    $date date("Y-m-d H:i:s");
            
    $id $_SESSION['u_id'];
            
    $creator $_SESSION['u_uid'];
            
    $reply_content $_POST['reply_content'];
            
    $cid $_POST['cid'];
            
    $tid $_POST['tid'];
            
    $limit 1;
            
    $email ='';
            

            
    $sql "INSERT INTO posts (category_id, topic_id, post_creator, post_content, post_date) VALUES (?,?,?,?,?);";

            if (!
    mysqli_stmt_prepare($stmt$sql)) {
                       echo 
    'SQL error';
                       
                    } else {
                        
    mysqli_stmt_bind_param($stmt"iisss"$cid$tid$creator$reply_content$date);
                        
    mysqli_stmt_execute($stmt);

                    

                        
    $sql2 "UPDATE categories
                                 SET last_post_date = ?, last_user_posted = ?
                                 WHERE id = ?
                                 LIMIT ?
                                 "
    ;

                        if (!
    mysqli_stmt_prepare($stmt$sql2)) {
                       echo 
    'SQL error';
                       
                    } else {
                        
    mysqli_stmt_bind_param($stmt"ssii"$date$creator$cid$limit);
                        
    mysqli_stmt_execute($stmt);
                        


                        
    $sql3 "SELECT * FROM topics WHERE topic_creator = ? AND topic_title = ?;";

                        if (!
    mysqli_stmt_prepare($stmt$sql3)) {
                       echo 
    'SQL error';
                       
                    } else {
                        
    mysqli_stmt_bind_param($stmt"ss"$creator$tic);
                        
    mysqli_stmt_execute($stmt);
                        
    $result mysqli_stmt_get_result($stmt);
                       

                        while (
    $row mysqli_fetch_assoc($result)) {

                        
    $reply $row['topic_reply'];
                        
    $newreply $reply 1;    

                        
    $sql4 "UPDATE topics
                                 SET topic_reply_date = ?, topic_last_user = ?, topic_reply = ?
                                 WHERE id = ?
                                 LIMIT ?
                                "
    ;
                         if (!
    mysqli_stmt_prepare($stmt$sql4)) {
                          echo 
    'SQL error';
                       
                    } else {
                        
                        
    mysqli_stmt_bind_param($stmt"ssiii"$date$creator$newreply$tid$limit);
                        
    mysqli_stmt_execute($stmt);

                  
                        
    // Email Sending 

                        
    $sql5 "SELECT post_creator FROM posts WHERE category_id = ? AND topic_id = ? GROUP BY post_creator;";

                        if (!
    mysqli_stmt_prepare($stmt$sql5)) {
                       echo 
    'SQL error';
                       
                    } else {
                        
    mysqli_stmt_bind_param($stmt"ii"$cid$tid);
                        
    mysqli_stmt_execute($stmt);
                        
    $result4 mysqli_stmt_get_result($stmt);
                        
    $userids = array();
                        while (
    $row4 mysqli_fetch_assoc($result4)) {
                          
                          
    $userids[] .= $row4['post_creator'];


                        }

                        foreach (
    $userids as $key) {
                            
    $forum_notification 1;
                            
    $limit 1;
                          
                            

                            
    $sql6 "SELECT user_uid, user_email FROM users WHERE user_uid = ? AND forum_notification = ? LIMIT ?;";

                    if (!
    mysqli_stmt_prepare($stmt$sql6)) {
                       echo 
    'SQL error';
                       
                    } else {
                        
    mysqli_stmt_bind_param($stmt"ssi"$key$forum_notification$limit);
                        
    mysqli_stmt_execute($stmt);
                        
    $result5 mysqli_stmt_get_result($stmt);
                        
    $resultCheck5 mysqli_num_rows($result5);
                     
                        
                        if (
    $resultCheck5 ) {

                            while(
    $row5 mysqli_fetch_assoc($result5)) {

                               if (
    $row5['user_uid'] != $creator) {

                              
    $email .= $row5['user_email']." ,";
                               
                            

                               
                        
                           } 



                           }

     
                           
                        }
    }

        }                
                       
    }

       
                       


        

        
    }

    $email substr($email0, (strlen($email) - 2));

    $company "pianocourse101@hotmail.com";
                        
    $subject "Forum reply";
                        
    $mailTo $email;
                        
    $bcc $email;
                        
    $headers "From: ".$company;
                        
    $headers .= "\r\nBcc: {$bcc}";
                        
    $txt "Hello ".$_SESSION['u_first']." ".$_SESSION['u_last']."! \n\n Someone has replied to a topic you were apart of.";

                        
    mail($mailTo$subject$txt$headers);
                

    echo 
    "<p>Your reply has been successfully posted. <a href='view_topic.php?cid=".$cid."&tid=".$tid."'>Click here to return to the topic.</a></p>";









    }
     }
    }
    }
    }
    }

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,715
    Member #
    5580
    Liked
    717 times
    This is way too hard for someone like me to troubleshoot without actually seeing the SQL database and all of the scripts.
    You could be making it harder than it needs to be ... but I'm not sure what all of your database tables look like.



Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 03:19 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com