Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Commenting system

    Hi... I have a php posting system, but I need a commenting system. I know how the comments would be added but I need to know how tey'd be attached to the right post. Here's the code

    PHP Code:
     require_once('appvars.php');
      require_once('connectvars.php');

      // Make sure the user is logged in before going any further.
      if (!isset($_SESSION['user_id'])) {
        echo '<p class="login">Please <a href="login.php">log in</a> to access this page.</p>';
        exit();
      }
      else {
        echo('<p class="login">You are logged in as ' . $_SESSION['username'] . '. <a href="logout.php">Log out</a>.</p>');
      }

      // Connect to the database
    $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die('could not connect to mysql '.mysqli_connect_error());

    // Grab the profile data from the database
    $query = "SELECT username, rank, gender, picture FROM kaoscraft_user WHERE user_id = '" . $_SESSION['user_id'] . "'";
        $data = mysqli_query($dbc, $query);
          $row = mysqli_fetch_array($data);
          $username = $row['username'];
          $rank = $row['rank'];
          $gender = $row['gender'];
          $picture = $row['picture'];



      if (isset($_POST['submit'])) {
        // Grab the post data from the POST
         $post1 = mysqli_real_escape_string($dbc, trim($_POST['post1']));
         $title = mysqli_real_escape_string($dbc, trim($_POST['title']));
         $category = mysqli_real_escape_string($dbc, trim($_POST['category']));

        // Update the post data in the database
          if (!empty($post1) && !empty($title)) {
            // Only set the picture column if there is a new picture
        $query = "INSERT INTO kaoscraft_posts (`username`, `rank`, `gender`, `picture`, `post_date`, `title`, `post`, `category`) VALUES ('$username', '$rank', '$gender', '$picture', NOW(), '$title', '$post1', '$category')";
            mysqli_query($dbc, $query);

            // Confirm success with the user
            echo '<p>Your post has been successfully added. Would you like to <a href="viewpost.php">view all of the posts</a>?</p>';

            mysqli_close($dbc);
            exit();
          }
          else {
            echo '<p class="error">You must enter information into all of the fields.</p>';
          }
      } // End of check for form submission

      mysqli_close($dbc);
    ?>  
      <form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
        <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo MM_MAXFILESIZE?>" />
        <fieldset>
          <legend>Post Here:</legend>
            <label type="hidden" for="title">Title:</label><br />
            <input type="text" name="title"><br /><br />
          <select id="category" name="category">
            <option value="G" <?php if (!empty($category) && $category == 'G') echo 'selected = "selected"'?>>General</option>
            <option value="Srv" <?php if (!empty($category) && $category == 'G') echo 'selected = "selected"'?>>Server</option>
            <option value="SA" <?php if (!empty($category) && $category == 'G') echo 'selected = "selected"'?>>Staff App</option>
          </select><br /><br />
          <label type="hidden" for="post1">Post Content:</label><br />
          <textarea rows="4"  name="post1" id="post1" cols="50"></textarea><br />
        </fieldset>
        <input type="submit" value="Save Post" name="submit" />     
      </form>
       </div>

  • #2
    Regular Coder
    Join Date
    Sep 2002
    Posts
    456
    Thanks
    0
    Thanked 20 Times in 20 Posts
    using post id, just add column to your comments and send post id to comment form or posting.
    NO Limits!! DHCreationStation.com
    ------------------------------------------------------------
    Broken items wanted for tinkerin'! PostItNow@BrokenEquipment.com
    Global Complaint Dept.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •