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
    Regular Coder
    Join Date
    Feb 2012
    Posts
    123
    Thanks
    19
    Thanked 3 Times in 3 Posts

    Question Posts Disappearing After Enter Problem

    I have been working on this script forever it seems. I have it where it will post messages and comments from the user ID that is logged into the system. There are two issues that I'm unable to figure out. I've got one hair left on my head

    1. Userpics and comments show up, but the username does not show up until "AFTER" you refresh the page. It should show up when you make a post or a comment.

    2. For some reason, my user pic and ID is the only one that remains on all comments and posts. When I log into another account, and make a new post, it posts to the wall, using that persons user pic, but when you refresh, the entire post disappears. Commenting is okay. It stays there, but still, problem one is still an issue with the commenting as well.

    I hope that made sense. Below are all the files that I use to work with all comments and posts. I know there is a lot of information here to sort through, but if you can help, that would be great. Thank you!


    loadmessages.php
    PHP Code:
     <?php
    //Loading Comments link with load_updates.php 
    foreach($updatesarray as $data)
     {
     
    $msg_id=$data['msg_id'];
     
    $message=tolink(htmlentities($data['message']));
      
    $time=$data['created'];
     
    $uid=$data['uid_fk'];
       
    $id=$uid;
     
    $commentsarray=$Wall->Comments($msg_id);
    ?>

    <script type="text/javascript"> 
    $(document).ready(function(){$("#stexpand<?php echo $msg_id;?>").oembed("<?php echo  $orimessage?>",{maxWidth: 400, maxHeight: 300});});
    </script>
    <div class="stbody" id="stbody<?php echo $msg_id;?>">

    <div class="stimg">
    <img src="members/<?=$id?>/image01.jpg" width="54px"></div> 
    <div class="sttext">
    <a class="stdelete" href="#" id="<?php echo $msg_id;?>" title="Delete update">X</a>
    <b><?php echo $username;?></b> <?php echo $message;?>
    <div class="sttime"><?php time_stamp($time);?> | <a href='#' class='commentopen' id='<?php echo $msg_id;?>' title='Comment'>Comment </a></div> 

    <div id="stexpandbox">
    <div id="stexpand<?php echo $msg_id;?>"></div>
    </div>

    <div class="commentcontainer" id="commentload<?php echo $msg_id;?>">

    <?php include('load_comments.php'?>

    </div>
    <div class="commentupdate" style='display:none' id='commentbox<?php echo $msg_id;?>'>
    <div class="stcommentimg">
    <img src="<?php echo $face;?>" class='small_face'/>
    </div> 
    <div class="stcommenttext" >
    <form method="post" action="">

    <textarea name="comment" class="comment" maxlength="200"  id="ctextarea<?php echo $msg_id;?>"></textarea>
    <br />
    <input type="submit"  value=" Comment "  id="<?php echo $msg_id;?>" class="comment_button"/>
    </form>

    </div>
    </div>

    </div> 
    </div>

    <?php

      
    }
    ?>
    messageajax.php
    PHP Code:
    <?php
    error_reporting
    (0);
    include_once 
    'includes/db.php';
    include_once 
    'includes/functions.php';
    include_once 
    'includes/tolink.php';
    include_once 
    'includes/time_stamp.php';
    include_once 
    'session.php';

    $Wall = new Wall_Updates();
    if(isSet(
    $_POST['update']))
    {
    $update=$_POST['update'];
    $data=$Wall->Insert_Update($uid,$update);

    if(
    $data)
    {
    $msg_id=$data['msg_id'];
    $message=tolink(htmlentities($data['message']));
    $time=$data['created'];
    $uid=$data['uid_fk'];
      
    $id=$uid;
    //$commentsarray=$Wall->Comments($msg_id);
    ?>
    <div class="stbody" id="stbody<?php echo $msg_id;?>">
    <div class="stimg">
    <img src="members/<?=$id?>/image01.jpg" width="54px"></div> 
    <div class="sttext">
    <a class="stdelete" href="#" id="<?php echo $msg_id;?>" title='Delete update'>X</a>
    <b><?php echo $username;?></b> <?php echo $message;?>
    <div class="sttime"><?php time_stamp($time);?> | <a href='#' class='commentopen' id='<?php echo $msg_id;?>' title='Comment'>Comment </a></div> 
    <div id="stexpandbox">
    <div id="stexpand"></div>
    </div>
    <div class="commentcontainer" id="commentload<?php echo $msg_id;?>">
    <?php// include('load_comments.php') ?>
    </div>
    <div class="commentupdate" style='display:none' id='commentbox<?php echo $msg_id;?>'>
    <div class="stcommentimg">
    <img src="<?php echo $face;?>" class='small_face'/>
    </div> 
    <div class="stcommenttext" >
    <form method="post" action="">
    <textarea name="comment" class="comment" maxlength="200"  id="ctextarea<?php echo $msg_id;?>"></textarea>
    <br />
    <input type="submit"  value=" Comment "  id="<?php echo $msg_id;?>" class="comment_button"/>
    </form>
    </div>
    </div>
    </div> 
    </div>
    <?php
    }
    }
    ?>
    loadcomments.php
    PHP Code:
    <?php
    //Loading Comments link with load_updates.php 
    foreach($commentsarray as $cdata)
     {
     
    $com_id=$cdata['com_id'];
     
    $comment=tolink(htmlentities($cdata['comment']));
      
    $time=$cdata['created'];   
      
    $uid=$cdata['uid_fk'];
      
    $id=$uid;
      
     
    ?>
     
     <script type="text/javascript"> 
    $(document).ready(function(){$("#stexpand<?php echo $com_id;?>").oembed("<?php echo  $orimessage?>",{maxWidth: 400, maxHeight: 300});});
    </script>

    <div class="stcommentbody" id="stcommentbody<?php echo $com_id?>">
    <div class="stcommentimg">
    <img src="members/<?=$id?>/image01.jpg" width="40px"></div> 
    <div class="stcommenttext">
    <a class="stcommentdelete" href="#" id='<?php echo $com_id?>' title='Delete Comment'>X</a>
    <b><?php echo $username?></b> <?php echo $comment?>
    <div class="stcommenttime"><?php time_stamp($time); ?></div> 
    </div>
    </div>
    <?php 
    }
    ?>
    commentajax.php
    PHP Code:
    <?php
    //Load latest comment 
    error_reporting(0);
    include_once 
    'includes/db.php';
    include_once 
    'includes/functions.php';
    include_once 
    'includes/tolink.php';
    include_once 
    'includes/time_stamp.php';
    include_once 
    'session.php';

    $Wall = new Wall_Updates();
    if(isSet(
    $_POST['comment']))
    {
    $comment=$_POST['comment'];
    $msg_id=$_POST['msg_id'];
    $cdata=$Wall->Insert_Comment($uid,$msg_id,$comment);
    if(
    $cdata)
    {
    $com_id=$cdata['com_id'];
     
    $comment=tolink(htmlentities($cdata['comment'] ));
     
    $time=$cdata['created'];
     
    $uid=$cdata['uid_fk'];
       
    $id=$uid;
     
    ?>
    <div class="stcommentbody" id="stcommentbody<?php echo $com_id?>">
    <div class="stcommentimg">
    <img src="members/<?=$id?>/image01.jpg" width="45px"></div> 
    <div class="stcommenttext">
    <a class="stcommentdelete" href="#" id='<?php echo $com_id?>'>X</a>
    <b><?php echo $username?></b> <?php echo $comment?>
    <div class="stcommenttime"><?php time_stamp($time); ?></div> 
    </div>
    </div>
    <?php
    }
    }
    ?>
    functions.php
    PHP Code:
    <?php

    //Wall_Updates

    class Wall_Updates {

         
    // Updates       
          
    public function Updates($uid
        {
            
    $query mysql_query("SELECT M.msg_id, M.uid_fk, M.message, M.created, U.username FROM messages M, users U  WHERE M.uid_fk=U.uid and M.uid_fk='$uid' order by M.msg_id desc ") or die(mysql_error());
             while(
    $row=mysql_fetch_array($query))
            
    $data[]=$row;
            return 
    $data;
            
        }
        
    //Comments
           
    public function Comments($msg_id
        {
            
    $query mysql_query("SELECT C.com_id, C.uid_fk, C.comment, C.created, U.username FROM comments C, users U WHERE C.uid_fk=U.uid and C.msg_id_fk='$msg_id' order by C.com_id asc ") or die(mysql_error());
           while(
    $row=mysql_fetch_array($query))
            
    $data[]=$row;
            if(!empty(
    $data))
            {
           return 
    $data;
             }
        }

        
    //Insert Update
        
    public function Insert_Update($uid$update
        {
        
    $update=htmlentities($update);
           
    $time=time();
            
    $query mysql_query("SELECT msg_id,message FROM `messages` WHERE uid_fk='$uid' order by msg_id desc limit 1") or die(mysql_error());
            
    $result mysql_fetch_array($query);
            
            if (
    $update!=$result['message']) {
                
    $query mysql_query("INSERT INTO `messages` (message, uid_fk, created) VALUES ('$update', '$uid','$time')") or die(mysql_error());
                
    $newquery mysql_query("SELECT M.msg_id, M.uid_fk, M.message, M.created, U.username FROM messages M, users U where M.uid_fk=U.uid and M.uid_fk='$uid' order by M.msg_id desc limit 1 ");
                
    $result mysql_fetch_array($newquery);
                 return 
    $result;
            } 
            else
            {
                     return 
    false;
            }
           
        }
        
        
    //Delete update
            
    public function Delete_Update($uid$msg_id
        {
            
    $query mysql_query("DELETE FROM `comments` WHERE msg_id_fk = '$msg_id' ") or die(mysql_error());
            
    $query mysql_query("DELETE FROM `messages` WHERE msg_id = '$msg_id' and uid_fk='$uid'") or die(mysql_error());
            return 
    true;
                     
        }
        
        
    //Insert Comments
        
    public function Insert_Comment($uid,$msg_id,$comment
        {
        
    $comment=htmlentities($comment);
                   
    $time=time();

            
    $query mysql_query("SELECT com_id,comment FROM `comments` WHERE uid_fk='$uid' and msg_id_fk='$msg_id' order by com_id desc limit 1 ") or die(mysql_error());
            
    $result mysql_fetch_array($query);
        
            if (
    $comment!=$result['comment']) {
                
    $query mysql_query("INSERT INTO `comments` (comment, uid_fk,msg_id_fk,created) VALUES ('$comment', '$uid','$msg_id','$time')") or die(mysql_error());
                
    $newquery mysql_query("SELECT C.com_id, C.uid_fk, C.comment, C.msg_id_fk, C.created, U.username FROM comments C, users U where C.uid_fk=U.uid and C.uid_fk='$uid' and C.msg_id_fk='$msg_id' order by C.com_id desc limit 1 ");
                
    $result mysql_fetch_array($newquery);
             
               return 
    $result;
            } 
            else
            {
            return 
    false;
            }
           
        }
        
        
    //Delete Comments
            
    public function Delete_Comment($uid$com_id
        {
            
    $query mysql_query("DELETE FROM `comments` WHERE uid_fk='$uid' and com_id='$com_id'") or die(mysql_error());
            return 
    true;
                     
        }

    }

    ?>
    If anyone could assist, I would appreciate it. Thanks.

  • #2
    Regular Coder
    Join Date
    Feb 2012
    Posts
    123
    Thanks
    19
    Thanked 3 Times in 3 Posts
    Not sure if they are needed, but they do work with the posts and comments.

    delete_comment_ajax.php
    PHP Code:
     <?php
    //Load latest update 
    error_reporting(0);
    include_once 
    'includes/db.php';
    include_once 
    'includes/functions.php';
    include_once 
    'includes/tolink.php';
    include_once 
    'includes/time_stamp.php';
    include_once 
    'session.php';
    $Wall = new Wall_Updates();
    if(isSet(
    $_POST['com_id']))
    {
    $com_id=$_POST['com_id'];
    $data=$Wall->Delete_Comment($uid,$com_id);
    echo 
    $data;

    }
    ?>
    delete_message_ajax.php
    PHP Code:
     <?php
    //Load latest update 
    error_reporting(0);
    include_once 
    'includes/db.php';
    include_once 
    'includes/functions.php';
    include_once 
    'includes/tolink.php';
    include_once 
    'includes/time_stamp.php';
    include_once 
    'session.php';
    $Wall = new Wall_Updates();
    if(isSet(
    $_POST['msg_id']))
    {
    $msg_id=$_POST['msg_id'];
    $data=$Wall->Delete_Update($uid,$msg_id);
    echo 
    $data;

    }
    ?>


  •  

    Posting Permissions

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