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.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 20
  1. #1
    Junior Member
    Join Date
    Feb 2014
    Location
    Chicago
    Posts
    18
    Member #
    38477

    Help with a "posting" website

    I made a post a little while back and i just made some progress with my site, I just need a little info to finish it.

    Its a website im making for my friends and i have it setup for registering users and login, I just need the posting part. So, I believe I need help figuring out how to make a text area submit to a database? and then show text entered in it... if that makes sense. Simply, I want to have it possible to type something in the text area, submit it, then have it show up below.
    maybe a better idea with this pic: View image: site
    WWW.sidebet.mjrwebdesign.net
    Thanks for helping!
    Last edited by mjrzasa; Apr 18th, 2014 at 03:27 PM. Reason: fixing

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,693
    Member #
    5580
    Liked
    717 times
    A lot of choices left to make ....

    Does it use only plain text, or rich text, like the "Quick Reply" I'm using now to type this post?

    Does the post appear without any moderation?

    Can spammers register and post spam?

    Is their any filtering (censorship) involved?

    How much can they post (length of post)?

    Are photos involved, or links to videos, or links to anywhere else?

    Are Avatars used?

    Is Captcha used?

    Do the posts appear "single", or are their 'posts', and replies to 'posts'? (nested posts)


  4. #3
    Junior Member
    Join Date
    Feb 2014
    Location
    Chicago
    Posts
    18
    Member #
    38477
    Thanks for the reply. I'm looking for something relatively simple. To answer the questions: plain text, no quick reply, no moderation, no spam, no images, no avatars, no nested posts. Just simply to show the text they input with a time stamp and username shown. Thanks
    Last edited by mjrzasa; Apr 18th, 2014 at 03:25 PM. Reason: didn't finish

  5. #4
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,693
    Member #
    5580
    Liked
    717 times
    Here's a nice simple one:
    Simple AJAX Commenting System | Tutorialzine

    I found it via Google ... there are dozens of them.

    The AJAX one looks nice.


  6. #5
    Junior Member
    Join Date
    Feb 2014
    Location
    Chicago
    Posts
    18
    Member #
    38477
    Thank yoso much for that link, i used it and its working nearly perfectly. Just a few things I still need help with

    Im trying to have it so in the posts, it posts the username for everyone. Currently it posts and posts time, I just want it to also post the username. The html that gets put in through php reference (i think) is:
    <div class="comment">

    <div class="name">'.$link_open.$d['name'].$link_close.'</div>
    <div class="date" title="Added at '.date('H:i \o\n d M Y',$d['dt']).'">'.date('d M Y',$d['dt']).'</div>
    <p>'.$d['body'].'</p>
    </div>

    That posts the date with the person's comment. Now I tried testing this code:
    <?= $fgmembersite->UserFullName();?>

    But it shows up as:
    UserFullName();?>

    This code works fine on another part of the page, the right side where it welcomes the user. I do not understand why it doesnt work, maybe because it is inside another php code...?

    On my server: I have the homepage "login-home.php" and <?= $fgmembersite->UserFullName();?> references to "include/fgmembersite.php" and my posts reference to "commentclass.php"

    and <?= $fgmembersite->UserFullName();?> does not work correctly when inside the posts html that references "commentclass.php"

    hopefully i described that thoroughly enough to be understandable thanks

  7. #6
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,693
    Member #
    5580
    Liked
    717 times
    I just realize they use "Gravatar" .... but that's OK.

    You're saying the user's name shows up in one script, but not another?

    Try displaying the name without any link parts to it ... like this ...

    Code:
    <div class="comment">
    <div class="name">'.$d['name'].'</div>
    <div class="date" title="Added at '.date('H:i \o\n d M Y',$d['dt']).'">'.date('d M Y',$d['dt']).'</div>
     <p>'.$d['body'].'</p>
      </div>
    And if you could show me a demo page of YOUR working comment thing, that would be nice.

    oh, and make sure you didn't set the font color of 'name' to the same as your page.
    Last edited by mlseim; Apr 20th, 2014 at 10:10 AM.


  8. #7
    Junior Member
    Join Date
    Feb 2014
    Location
    Chicago
    Posts
    18
    Member #
    38477
    Hi. The thing is with that "name" they are calling, it is referring to something I removed. In their tutorial, they have a small form where you fill in your name email URL and comment, then when you submit a post it shows all that info in your post. I edited that to only use the comment field. The username I am trying to get in the post is actually something I found in another tutorial.
    PS I also took out the avatar, but I made sure everything continued to work along the way.

  9. #8
    Junior Member
    Join Date
    Feb 2014
    Location
    Chicago
    Posts
    18
    Member #
    38477
    This is the page that has a bunch of functions that makes <?= $fgmembersite->UserFullName();?> work outside of the comment box im working on. It prints what people register with as their name, my final goal is to get it to print what people register their username as, but ill try to figure that out once i get the userfullname working.
    fg_membersite.php (i cut off the bottom half of this code because my post was too long)
    PHP Code:
    <?PHP
    /*
        Registration/Login script from HTML Form Guide
        V1.0

        This program is free software published under the
        terms of the GNU Lesser General Public License.
        http://www.gnu.org/copyleft/lesser.html
        

    This program is distributed in the hope that it will
    be useful - WITHOUT ANY WARRANTY; without even the
    implied warranty of MERCHANTABILITY or FITNESS FOR A
    PARTICULAR PURPOSE.

    For updates, please visit:
    http://www.html-form-guide.com/php-form/php-registration-form.html
    http://www.html-form-guide.com/php-form/php-login-form.html

    */
    require_once("class.phpmailer.php");
    require_once(
    "formvalidator.php");

    class 
    FGMembersite
    {
        var 
    $admin_email;
        var 
    $from_address;
        
        var 
    $username;
        var 
    $pwd;
        var 
    $database;
        var 
    $tablename;
        var 
    $connection;
        var 
    $rand_key;
        
        var 
    $error_message;
        
        
    //-----Initialization -------
        
    function FGMembersite()
        {
            
    $this->sitename 'YourWebsiteName.com';
            
    $this->rand_key '0iQx5oBk66oVZep';
        }
        
        function 
    InitDB($host,$uname,$pwd,$database,$tablename)
        {
            
    $this->db_host  $host;
            
    $this->username $uname;
            
    $this->pwd  $pwd;
            
    $this->database  $database;
            
    $this->tablename $tablename;
            
        }
        function 
    SetAdminEmail($email)
        {
            
    $this->admin_email $email;
        }
        
        function 
    SetWebsiteName($sitename)
        {
            
    $this->sitename $sitename;
        }
        
        function 
    SetRandomKey($key)
        {
            
    $this->rand_key $key;
        }
        
        
    //-------Main Operations ----------------------
        
    function RegisterUser()
        {
            if(!isset(
    $_POST['submitted']))
            {
               return 
    false;
            }
            
            
    $formvars = array();
            
            if(!
    $this->ValidateRegistrationSubmission())
            {
                return 
    false;
            }
            
            
    $this->CollectRegistrationSubmission($formvars);
            
            if(!
    $this->SaveToDatabase($formvars))
            {
                return 
    false;
            }
            
            if(!
    $this->SendUserConfirmationEmail($formvars))
            {
                return 
    false;
            }

            
    $this->SendAdminIntimationEmail($formvars);
            
            return 
    true;
        }

        function 
    ConfirmUser()
        {
            if(empty(
    $_GET['code'])||strlen($_GET['code'])<=10)
            {
                
    $this->HandleError("Please provide the confirm code");
                return 
    false;
            }
            
    $user_rec = array();
            if(!
    $this->UpdateDBRecForConfirmation($user_rec))
            {
                return 
    false;
            }
            
            
    $this->SendUserWelcomeEmail($user_rec);
            
            
    $this->SendAdminIntimationOnRegComplete($user_rec);
            
            return 
    true;
        }    
        
        function 
    Login()
        {
            if(empty(
    $_POST['username']))
            {
                
    $this->HandleError("UserName is empty!");
                return 
    false;
            }
            
            if(empty(
    $_POST['password']))
            {
                
    $this->HandleError("Password is empty!");
                return 
    false;
            }
            
            
    $username trim($_POST['username']);
            
    $password trim($_POST['password']);
            
            if(!isset(
    $_SESSION)){ session_start(); }
            if(!
    $this->CheckLoginInDB($username,$password))
            {
                return 
    false;
            }
            
            
    $_SESSION[$this->GetLoginSessionVar()] = $username;
            
            return 
    true;
        }
        
        function 
    CheckLogin()
        {
             if(!isset(
    $_SESSION)){ session_start(); }

             
    $sessionvar $this->GetLoginSessionVar();
             
             if(empty(
    $_SESSION[$sessionvar]))
             {
                return 
    false;
             }
             return 
    true;
        }
        
        function 
    UserFullName()
        {
            return isset(
    $_SESSION['name_of_user'])?$_SESSION['name_of_user']:'';
        }
        
        function 
    UserEmail()
        {
            return isset(
    $_SESSION['email_of_user'])?$_SESSION['email_of_user']:'';
        }
           
    }
    ?>
    the function is:
    PHP Code:
    function UserFullName()
        {
            return isset(
    $_SESSION['name_of_user'])?$_SESSION['name_of_user']:'';
        } 
    Again, It works on some parts of the page but when I try to add it to "comment.class.php" it fails

    The php file that posts the comments and time stamp and where i want username to come up is:
    comment.class.php
    PHP Code:
    <?php

    class Comment
    {
        private 
    $data = array();
        
        public function 
    __construct($row)
        {
            
    /*
            /    The constructor
            */
            
            
    $this->data $row;
        }
        
        public function 
    markup()
        {
            
    /*
            /    This method outputs the XHTML markup of the comment
            */
            
            // Setting up an alias, so we don't have to write $this->data every time:
            
    $d = &$this->data;
            
            
    $link_open '';
            
    $link_close '';
            
            if(
    $d['url']){
                
                
    // If the person has entered a URL when adding a comment,
                // define opening and closing hyperlink tags
                
                
    $link_open '<a href="'.$d['url'].'">';
                
    $link_close =  '</a>';
            }
            
            
    // Converting the time to a UNIX timestamp:
            
    $d['dt'] = strtotime($d['dt']);
            
            
    // Needed for the default gravatar image:
            
    $url 'http://'.dirname($_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"]).'/img/default_avatar.gif';
            
            return 
    '
            
                <div class="comment">
                                    
                    <div class="name">'
    .$link_open.$d['name'].$link_close.'</div>
                    <div class="date" title="Added at '
    .date('H:i \o\n d M Y',$d['dt']).'">'.date('d M Y',$d['dt']).'</div>
                    <p>'
    .$d['body'].'</p>
                </div>


            '
    ;
        }
        
        public static function 
    validate(&$arr)
        {
            
    /*
            /    This method is used to validate the data sent via AJAX.
            /
            /    It return true/false depending on whether the data is valid, and populates
            /    the $arr array passed as a paremter (notice the ampersand above) with
            /    either the valid input data, or the error messages.
            */
            
            
    $errors = array();
            
    $data    = array();
            
            
    // Using the filter_input function introduced in PHP 5.2.0
            
            
            
            // Using the filter with a custom callback function:
            
            
    if(!($data['body'] = filter_input(INPUT_POST,'body',FILTER_CALLBACK,array('options'=>'Comment::validate_text'))))
            {
                
    $errors['body'] = 'Please enter a comment.';
            }
            
                    
            if(!empty(
    $errors)){
                
                
    // If there are errors, copy the $errors array to $arr:
                
                
    $arr $errors;
                return 
    false;
            }
            
            
    // If the data is valid, sanitize all the data and copy it to $arr:
            
            
    foreach($data as $k=>$v){
                
    $arr[$k] = mysql_real_escape_string($v);
            }
            
            
    // Ensure that the email is lower case:
            
            
    $arr['email'] = strtolower(trim($arr['email']));
            
            return 
    true;
            
        }

        private static function 
    validate_text($str)
        {
            
    /*
            /    This method is used internally as a FILTER_CALLBACK
            */
            
            
    if(mb_strlen($str,'utf8')<1)
                return 
    false;
            
            
    // Encode all html special characters (<, >, ", & .. etc) and convert
            // the new line characters to <br> tags:
            
            
    $str nl2br(htmlspecialchars($str));
            
            
    // Remove the new line characters that are left
            
    $str str_replace(array(chr(10),chr(13)),'',$str);
            
            return 
    $str;
        }

    }

    ?>
    Last edited by mjrzasa; Apr 20th, 2014 at 11:34 AM.

  10. #9
    Junior Member
    Join Date
    Feb 2014
    Location
    Chicago
    Posts
    18
    Member #
    38477
    So in my database I have
    id_user, name, email, phone_number, username, password, confirmcode. I tried changing the code from:

    PHP Code:
    function UserFullName() 
        { 
            return isset(
    $_SESSION['name_of_user'])?$_SESSION['name_of_user']:''
    to:

    PHP Code:
    function UserFullName() 
        { 
            return isset(
    $_SESSION['username_of_user'])?$_SESSION['username_of_user']:''
    So it would pull the username they registered with, but it doesnt work, it just shows up blank. HOWEVER, if I change it to:

    PHP Code:
    function UserFullName() 
        { 
            return isset(
    $_SESSION['email_of_user'])?$_SESSION['email_of_user']:''
    It correctly outputs the user's email address... CONFUSED

  11. #10
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,693
    Member #
    5580
    Liked
    717 times
    I should preface this with the fact that I'm not an expert at PHP 'classes'.

    In the script below, I am attempting to define the variable $name to be the SESSION variable in the 'constructor' portion of the class.

    Then, later on, $name is used to display the name.

    I have no way to test this, so save a safe copy of your original in case my example crashes. I'm not sure if session_start(); needs to be on top or not. Remove it if you get any "SESSION" errors.

    Code:
    <?php
    session_start();
    // not sure if you need the line above this or not?
    
    
    class Comment
    {
        private $data = array();
        
        public function __construct($row)
        {
            /*
            /    The constructor
            */
            
            $this->data = $row;
            $name = $_SESSION['name_of_user'];
        }
        
        public function markup()
        {
            /*
            /    This method outputs the XHTML markup of the comment
            */
            
            // Setting up an alias, so we don't have to write $this->data every time:
            $d = &$this->data;
            
            $link_open = '';
            $link_close = '';
            
            if($d['url']){
                
                // If the person has entered a URL when adding a comment,
                // define opening and closing hyperlink tags
                
                $link_open = '<a href="'.$d['url'].'">';
                $link_close =  '</a>';
            }
            
            // Converting the time to a UNIX timestamp:
            $d['dt'] = strtotime($d['dt']);
            
            // Needed for the default gravatar image:
            $url = 'http://'.dirname($_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"]).'/img/default_avatar.gif';
            
            return '
            
                <div class="comment">
                                    
                    <div class="name">'.$name.'</div>
                    <div class="date" title="Added at '.date('H:i \o\n d M Y',$d['dt']).'">'.date('d M Y',$d['dt']).'</div>
                    <p>'.$d['body'].'</p>
                </div>
    
    
            ';
        }
        
        public static function validate(&$arr)
        {
            /*
            /    This method is used to validate the data sent via AJAX.
            /
            /    It return true/false depending on whether the data is valid, and populates
            /    the $arr array passed as a paremter (notice the ampersand above) with
            /    either the valid input data, or the error messages.
            */
            
            $errors = array();
            $data    = array();
            
            // Using the filter_input function introduced in PHP 5.2.0
            
            
            
            // Using the filter with a custom callback function:
            
            if(!($data['body'] = filter_input(INPUT_POST,'body',FILTER_CALLBACK,array('options'=>'Comment::validate_text'))))
            {
                $errors['body'] = 'Please enter a comment.';
            }
            
                    
            if(!empty($errors)){
                
                // If there are errors, copy the $errors array to $arr:
                
                $arr = $errors;
                return false;
            }
            
            // If the data is valid, sanitize all the data and copy it to $arr:
            
            foreach($data as $k=>$v){
                $arr[$k] = mysql_real_escape_string($v);
            }
            
            // Ensure that the email is lower case:
            
            $arr['email'] = strtolower(trim($arr['email']));
            
            return true;
            
        }
    
        private static function validate_text($str)
        {
            /*
            /    This method is used internally as a FILTER_CALLBACK
            */
            
            if(mb_strlen($str,'utf8')<1)
                return false;
            
            // Encode all html special characters (<, >, ", & .. etc) and convert
            // the new line characters to <br> tags:
            
            $str = nl2br(htmlspecialchars($str));
            
            // Remove the new line characters that are left
            $str = str_replace(array(chr(10),chr(13)),'',$str);
            
            return $str;
        }
    
    }
    
    ?>






Page 1 of 2 1 2 LastLast

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 10:10 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com