Status Function [Comment Feature]!!!!!

Discussion in 'PHP' started by Spudster, May 26, 2012.

  1. #1
    I know that i should be learning myself but som help on certain things an also help someone learn so i can study on the code.

    Now ive made a status system and posts that a user has made tommorow i will add the links directly to there page.

    can someone please help with adding a feature where a user can comment on a post created.

    Thanks
     
    Spudster, May 26, 2012 IP
  2. akhileshbc

    akhileshbc Active Member

    Messages:
    98
    Likes Received:
    1
    Best Answers:
    5
    Trophy Points:
    75
    #2
    Hi,
    I am not sure whether I completely got you. What you want to have is a commenting system where users could comment a "status" posted by another user. Isn't it ?

    I assume you have a database. Create a table to keep track of the comments. One field would be for the message. One field would be for the "status" message's id(assuming you keep track of the status in another table). Another field for storing the user id and another one for storing the dateandtime.

    Now when a user adds a comment, it will be inserted as a new record in this table. And to list all the comments for a particular "status", query the db with a WHERE condition passing the "status" id.

    Hope you got the idea. What I mentioned is very simple, I believe. :)

    Good luck.
     
    akhileshbc, May 27, 2012 IP
  3. Spudster

    Spudster Peon

    Messages:
    96
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yes ive sort of get the idea then how will i get it to echo the comment on the status post :)

    And issue 2

    Hey im trying to make so users can edit there own pages or delete there own status posts, how do i do this??


    this code wont work/execute this function?

    <?php
    session_start();
    /* 
    DELETE.PHP
    Deletes a specific entry from the 'players' table
    */
    
    $get = $_GET['id'];
    // connect to the database
    mysql_connect ("localhost","root","");
    mysql_select_db ("pph") or die ("Could Not Select Database");
    
    
    
    // check if the 'id' variable is set in URL, and check that it is valid
    if (isset($_GET['id']) && is_numeric($_GET['id']))
    {
    // get id value
    $id = $_GET['id'];
    
    // select the entry
    mysql_query ("SELECT * FROM pages WHERE pid='$get'") or die ("Query Erro on line 21");
    
    ?>
    
    <?php
    
    $username = $_SESSION['username'];
    // Lets echo the tables (We need to make a new style soon 
    
    $con = mysql_connect("localhost","root","");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
    
    mysql_select_db("pph", $con);
    
    $result = mysql_query("SELECT * FROM pages");
    $result = mysql_query ("SELECT * FROM pages WHERE pid ='$get'") or die ("Query Error");
    
    while($row = mysql_fetch_array($result))
    {
    
    print ("Username<br>"); echo $row['pageowner'] . "<td> " . $row['pageinfo'];
    
    $query = mysql_query("SELECT * FROM pages WHERE pageowner='$username'") or die ("jhgfrw");
    $query1 = mysql_query("SELECT * FROM pages WHERE pageowner='$get'") or die ("jhgfrw");
    
    
    while($row = mysql_fetch_array($result))
    {
    
    echo $row['username'] . " " . $row['text']; 
    $row = mysql_fetch_array($query);
    
    echo "<br /><br><br>";
    
    
    }
    
    mysql_close($con);
    }
    }
    ?>
    PHP:
    i want it to say 'if user is in the pageowner table echo ("edit Page");
     
    Spudster, May 27, 2012 IP
  4. akhileshbc

    akhileshbc Active Member

    Messages:
    98
    Likes Received:
    1
    Best Answers:
    5
    Trophy Points:
    75
    #4
    Ok. :)

    For each post, pull the data from the db for that particular post(passing the post_id). Then echo the resulting query.
     
    akhileshbc, May 27, 2012 IP
  5. Spudster

    Spudster Peon

    Messages:
    96
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks for the quick post :)

    and heres the updated code

    
    heres the updated code its looking at all the tables, need it to look at one, I learn buy studying codes aswill... and if the users on the pageowner tables
    can someone please modify this todo this.
    [code]<?php
    session_start();
    $username = $_SESSION['username'];
    /* 
     DELETE.PHP
     Deletes a specific entry from the 'players' table
    */
    
    $get = $_GET['id'];
     // connect to the database
     mysql_connect ("localhost","root","");
     mysql_select_db ("pph") or die ("Could Not Select Database");
    
     
     
     // check if the 'id' variable is set in URL, and check that it is valid
     if (isset($_GET['id']) && is_numeric($_GET['id']))
     {
     // get id value
     $id = $_GET['id'];
     
     // select the entry
      mysql_query ("SELECT * FROM pages WHERE pid='$get'") or die ("Query Erro on line 21");
        $query = mysql_query("SELECT * FROM pages WHERE pageowner='$username'") or die ("jhgfrw");
    
       $row = mysql_fetch_array($query);
    
    if ($row['pageowner'] == $username)
    print ("kj");
      
     ?>
    
     <?php
    
     $username = $_SESSION['username'];
     // Lets echo the tables (We need to make a new style soon 
     
    $con = mysql_connect("localhost","root","");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("pph", $con);
    
    $result = mysql_query("SELECT * FROM pages");
    $result = mysql_query ("SELECT * FROM pages WHERE pid ='$get'") or die ("Query Error");
    
    while($row = mysql_fetch_array($result))
      {
     
      print ("Username<br>"); echo $row['pageowner'] . "<td> " .  $row['pageinfo'];
       
       $query = mysql_query("SELECT * FROM pages WHERE pageowner='$username'") or die ("jhgfrw");
       $query = mysql_query("SELECT * FROM pages WHERE pageowner='$$get'") or die ("jhgfrw");
    
      
      echo "<br /><br><br>";
    
    
    }
       
    mysql_close($con);
    }
    die ("");
    ?>[/code]
    PHP:
     
    Spudster, May 27, 2012 IP
  6. akhileshbc

    akhileshbc Active Member

    Messages:
    98
    Likes Received:
    1
    Best Answers:
    5
    Trophy Points:
    75
    #6
    Your code is a mess at the moment. You have to clean up a bit. :)

    There are some queries that don't have any effect.
    For example:
    $result = mysql_query("SELECT * FROM pages");
    $result = mysql_query ("SELECT * FROM pages WHERE pid ='$get'") or die ("Query Error");
    PHP:
    You are performing the query and assigning to the same variable. So the first resultset is overwritten by the second !

    Another thing is, you are directly using the value from the GET method, in your query. This will make your code prone to sql injections. Use mysql_real_escape_string() to escape the values or use prepared statements which is available in mysqli

    Avoid unnecessary code fragments and also do proper indenting. Because indenting will allow you as well as others to read the code without giving strain to the eyes. :)

    Good luck.
     
    Last edited: May 27, 2012
    akhileshbc, May 27, 2012 IP
  7. GHWebSolution

    GHWebSolution Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Hello,

    We have expert web designers & developers team in our company & we can develop that feature in your website according to your needs in given deadline with strong support. You can contact us at skype.

    Skype ID : DavidDavin9

    Regards
    G.H Web Solution
     
    GHWebSolution, May 27, 2012 IP
  8. Spudster

    Spudster Peon

    Messages:
    96
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    ok thanks i will try to contact soon.

    and who could modifi this for m :)
     
    Spudster, May 27, 2012 IP
  9. Spudster

    Spudster Peon

    Messages:
    96
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    this is my first PHP project im stil learning but think im doing will at the momment, When i get home from work and school i will fix the code up.

    But can someone please modfi it to do what it should do then i will patch the bugs/secuirty emploits over :)
     
    Spudster, May 27, 2012 IP
  10. akhileshbc

    akhileshbc Active Member

    Messages:
    98
    Likes Received:
    1
    Best Answers:
    5
    Trophy Points:
    75
    #10
    Hi,
    I don't think anyone would fix it for free.

    But if you might, you could improve the code by changing it with the suggestions that I put forward.
     
    akhileshbc, May 27, 2012 IP
  11. Spudster

    Spudster Peon

    Messages:
    96
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    So i would i do this instead of

    $result = mysql_query("SELECT * FROM pages");$result = mysql_query ("SELECT * FROM pages WHERE pid ='$get'") or die ("Query Error");

    DO THIS


    $result = mysql_query("SELECT * FROM pages");$result = mysql_query ("SELECT * FROM pages WHERE pid ='mysql_real_escape_string()") or die ("Query Error");

    i only want it to look at one table, so if i go to viewpage.php?id=1 then it will look at Page ID one and if the user is on the page owners table then echo Edit Page.


    Edit: Thanks I have just learnt a new function to use with php and thats more secure :)

    Please give me suggestions to get this feature working, or things i can add to get the appilication working.
     
    Spudster, May 27, 2012 IP
  12. akhileshbc

    akhileshbc Active Member

    Messages:
    98
    Likes Received:
    1
    Best Answers:
    5
    Trophy Points:
    75
    #12
    Avoid using variables inside those strings enclosed in double quotes. Try appending it using the dot operator. Otherwise, escape that variable by enclosing it in curly braces.

    This is an example of what you are doing now:
    
    $n = 'Akhilesh';
    
    echo "My name is $n";
    
    PHP:
    But I would suggest it like this:
    
    $n = 'Akhilesh';
    
    echo "My name is {$n}";
    
    PHP:
    Or this(I usually prefer this way):
    
    $n = 'Akhilesh';
    
    echo "My name is " . $n;
    
    PHP:
    Now regarding your query:
    
    $a = "abc";
    $a = "def";
    
    echo $a;
    
    PHP:
    What is the use of assigning the variable with the value "abc" ? Are we using it anywhere ? No ! So is there a need of multiple assignment operations like that ?

    Hope it helps :)
     
    akhileshbc, May 28, 2012 IP