heyhey01 Posted April 12, 2010 Share Posted April 12, 2010 I am building a site and part of the site has to be a feature where user can tell others about how their experience was kind of like the wall feature on facebook. How would i go about doing this because i am still new to php so i am not sure how to do it. Can anyone help? Quote Link to comment https://forums.phpfreaks.com/topic/198269-the-wall-feature/ Share on other sites More sharing options...
Ken2k7 Posted April 12, 2010 Share Posted April 12, 2010 Well, where do you want to start? It's pretty much just getting the data, storing it in the database and displaying it on the page. Think about all the places you need to display it and structure the database in a good way so querying it isn't a pain. I don't use Facebook a lot, so I probably don't know all the places where wall posts are displayed. Quote Link to comment https://forums.phpfreaks.com/topic/198269-the-wall-feature/#findComment-1040362 Share on other sites More sharing options...
TeddyKiller Posted April 12, 2010 Share Posted April 12, 2010 Facebooks wall feature, is basically like comments. Except you can comment on the comments... I don't get what you mean? Quote Link to comment https://forums.phpfreaks.com/topic/198269-the-wall-feature/#findComment-1040364 Share on other sites More sharing options...
heyhey01 Posted April 14, 2010 Author Share Posted April 14, 2010 Facebooks wall feature, is basically like comments. Except you can comment on the comments... I don't get what you mean? What i mean is i can get it so that users can write comments but when i go away from the page the comments dont save for later viewing by other users. Quote Link to comment https://forums.phpfreaks.com/topic/198269-the-wall-feature/#findComment-1041563 Share on other sites More sharing options...
trq Posted April 14, 2010 Share Posted April 14, 2010 What i mean is i can get it so that users can write comments but when i go away from the page the comments dont save for later viewing by other users. Â You need to use a persistent storage mechanism like a database or flat files of some sort. How else do you expect the data to persist? Quote Link to comment https://forums.phpfreaks.com/topic/198269-the-wall-feature/#findComment-1041565 Share on other sites More sharing options...
heyhey01 Posted April 14, 2010 Author Share Posted April 14, 2010 i already have a database ready. Quote Link to comment https://forums.phpfreaks.com/topic/198269-the-wall-feature/#findComment-1041645 Share on other sites More sharing options...
heyhey01 Posted April 14, 2010 Author Share Posted April 14, 2010 Here is the code i have made for the comment feature it says am getting a pares error where I have </body></html> i have changed the name of the database, user and password for posting here.  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html>  <head>   <meta http-equiv="Content-type" content="text/html;charset=UTF-8">   <meta name="author" content="">   <title></title>  <link rel="stylesheet" type="text/css" href="css1.css" />  </head> <body> <?php // calling session_start() the function which starts our authentication session session_start(); // connecting to mysql server // Connects to your Database mysql_connect("localhost", "r", "fff") or die(mysql_error()); mysql_select_db("ut") or die(mysql_error()); // defining getShouts() which is our function that gets all of our shouts function getcomments() { echo '<div align="center"> <table width="150" border="0" cellspacing="0" cellpadding="0">  <tr> <td> '; $query = mysql_query("SELECT * FROM comments ORDER BY commentid DESC LIMIT 10") or die(mysql_error()); while ($row = mysql_fetch_array($query) ) { $name = stripslashes($row['Name']); $comment = stripslashes($row['comment']); echo '<br><br>'; echo ' </td>  </tr>  <tr> <td height="10"> </td> <form name="comment" method="post" action="comment.php">  <div align="center"> <input name="name" type="text" id="name" value="Name" size="25" maxlength="10"><br> <input name="message" type="text" id="message" value="Message" size="25"><br> <input name="comment" type="submit" id="comment" value="comment!">  </div> </form> </td>  </tr>  </table>  </div> '; } // function getcomments // our processing if control statement if ( isset ( $_POST['comment'] ) ) { $name = addslashes($_POST['name']); $message = $_POST['message']; if ( ( isset($name) ) && ( isset($message) ) ) { mysql_query("INSERT INTO comment (Name, message) VALUES ( '$name', '$message' )") or die(mysql_error()); $_SESSION['has_posted'] = 'yes'; header("Location: comment.php"); // if required fields aren't empty, process into database } else { echo '<script>alert("Some fields were not filled out!");</script>'; header("Location: comment.php"); // if required fields were left empty, show an error dialog } } getcomments(); </body></html> ?> Quote Link to comment https://forums.phpfreaks.com/topic/198269-the-wall-feature/#findComment-1041693 Share on other sites More sharing options...
Ken2k7 Posted April 14, 2010 Share Posted April 14, 2010 ... uh ... Â Did it occur to you that </body></html> is not PHP code? Also, you're missing a closing brace for your while loop. Quote Link to comment https://forums.phpfreaks.com/topic/198269-the-wall-feature/#findComment-1041698 Share on other sites More sharing options...
heyhey01 Posted April 14, 2010 Author Share Posted April 14, 2010 ... uh ... Â Did it occur to you that </body></html> is not PHP code? Also, you're missing a closing brace for your while loop. yes it did occur to me and i have changed it to outside the php code and it has not made a difference. Quote Link to comment https://forums.phpfreaks.com/topic/198269-the-wall-feature/#findComment-1041716 Share on other sites More sharing options...
Ken2k7 Posted April 14, 2010 Share Posted April 14, 2010 Did you also fix the closing brace I told you about? Quote Link to comment https://forums.phpfreaks.com/topic/198269-the-wall-feature/#findComment-1041728 Share on other sites More sharing options...
heyhey01 Posted April 14, 2010 Author Share Posted April 14, 2010 Did you also fix the closing brace I told you about? i think i did but can u show me where its meant to go in case I have put it in the wrong place. Quote Link to comment https://forums.phpfreaks.com/topic/198269-the-wall-feature/#findComment-1041735 Share on other sites More sharing options...
TeddyKiller Posted April 14, 2010 Share Posted April 14, 2010 Post your current code. Quote Link to comment https://forums.phpfreaks.com/topic/198269-the-wall-feature/#findComment-1041769 Share on other sites More sharing options...
heyhey01 Posted April 14, 2010 Author Share Posted April 14, 2010 Here is my new code first one comment.php is just page with a form and the second page comments2.php is were the php code that is ment to display the the review but it does not just shows a blank page. comments.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> Â <head> Â Â <meta http-equiv="Content-type" content="text/html;charset=UTF-8"> Â Â <meta name="author" content=""> Â Â <title></title> Â <link rel="stylesheet" type="text/css" href="css1.css" /> Â </head> <body> <form action="comments2.php" method="post"> <tr><td>Username:</td><td> <input type="text" name="name" maxlength="60"> </td></tr><br /> <tr><td>jjj:</td><td> <input type="text" name="jjj" maxlength="60"> </td></tr><br /> <tr><td>Review:</td><td><br /> <TEXTAREA NAME="review" COLS=40 ROWS=15></TEXTAREA> <tr><th colspan=2><input type="submit" name="submit" value="SUBMIT"></th></tr> </table> </form> </body></html> names of certain things have been changed to post on here. Â Heres is the code for comments2 the names of certain things have been changed so i can post on here <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> Â <head> Â Â <meta http-equiv="Content-type" content="text/html;charset=UTF-8"> Â Â <meta name="author" content=""> Â Â <title></title> Â <link rel="stylesheet" type="text/css" href="css1.css" /> Â </head> <body> <?php // Connects to your Database mysql_connect("localhost", "gggg", "g") or die(mysql_error()); mysql_select_db("cd") or die(mysql_error()); // now we insert it into the database $insert = "INSERT INTO comments (name, ffffff, jjjjj) VALUES ('".$_POST['name']."', '".$_POST['fffff']."','".$_POST['jjjjj']."')"; $add_member = mysql_query($insert); $query = mysql_query("SELECT * FROM comments ORDER BY commentid DESC LIMIT 15") or die(mysql_error()); ($row = mysql_fetch_array($query) ) Â ?> </body></html> Quote Link to comment https://forums.phpfreaks.com/topic/198269-the-wall-feature/#findComment-1041870 Share on other sites More sharing options...
Ken2k7 Posted April 14, 2010 Share Posted April 14, 2010 You haven't printed anything in your second file. All you did was store stuff in variables. Quote Link to comment https://forums.phpfreaks.com/topic/198269-the-wall-feature/#findComment-1041876 Share on other sites More sharing options...
TeddyKiller Posted April 14, 2010 Share Posted April 14, 2010 You haven't printed anything out at all. Quote Link to comment https://forums.phpfreaks.com/topic/198269-the-wall-feature/#findComment-1041889 Share on other sites More sharing options...
heyhey01 Posted April 14, 2010 Author Share Posted April 14, 2010 You haven't printed anything out at all. how would i make it print off what i stored? Quote Link to comment https://forums.phpfreaks.com/topic/198269-the-wall-feature/#findComment-1042025 Share on other sites More sharing options...
Ken2k7 Posted April 14, 2010 Share Posted April 14, 2010 I suggest reading up on PHP 101 before attempting to code a feature similar to Facebook wall. If you don't even know how to print content to the page with PHP, you really shouldn't be writing this. Quote Link to comment https://forums.phpfreaks.com/topic/198269-the-wall-feature/#findComment-1042029 Share on other sites More sharing options...
heyhey01 Posted April 14, 2010 Author Share Posted April 14, 2010 I suggest reading up on PHP 101 before attempting to code a feature similar to Facebook wall. If you don't even know how to print content to the page with PHP, you really shouldn't be writing this. well i did not think having a comment box would be so hard. all i wanted it to do was to able the user to leave comments for others to see like they have on many sites. Quote Link to comment https://forums.phpfreaks.com/topic/198269-the-wall-feature/#findComment-1042030 Share on other sites More sharing options...
heyhey01 Posted April 15, 2010 Author Share Posted April 15, 2010 Here is the new code only problem is it wont display the comment it just saves it to the database. Please tell me what am doing wrong. name of database name has been changed.  <?php // Otherwise we connect to our Database mysql_connect("localhost", "t", "g") or die(mysql_error()); mysql_select_db("hhh") or die(mysql_error()); // check if POST data has been entered (meaning a comment was entered) if (isset ($_POST['submit'])) {   $comment = mysql_escape_string (trim ($_POST['comment']));     // enter the comment to the database   $sql = mysql_query ("INSERT INTO comments (id,comments) VALUES ('0','".$comment."')");   echo 'Your comment has been entered successfully!'; } else {   // POST data wasnt entered, so display the comments and comment form   // view comments from database   $sql = mysql_query ("SELECT * FROM comments");   while ($row = mysql_fetch_array ($sql)) {     echo $row['comments'].'<br />';   }   // display comment form   echo '<br /><br />   <form action="commentsnew.php" method="post">   Comments:<br />   <textarea name="comment" cols="40" rows="7"></textarea> <input type="submit" name="submit" value="SUBMIT">   </form>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/198269-the-wall-feature/#findComment-1042101 Share on other sites More sharing options...
heyhey01 Posted April 15, 2010 Author Share Posted April 15, 2010 I have the code sort of working but i just need it to display the user name as well as the comment. can someone show me how to get the username as well please. <html>  <head>   <meta http-equiv="Content-type" content="text/html;charset=UTF-8">   <meta name="author" content="">   <title></title>  <link rel="stylesheet" type="text/css" href="css1.css" />  </head> <body> <?php  // Otherwise we connect to our Database mysql_connect("localhost", "y", "j") or die(mysql_error()); mysql_select_db("h") or die(mysql_error()); // check if POST data has been entered (meaning a comment was entered) if (isset ($_POST['submit'])) {   $comment = mysql_escape_string (trim ($_POST['comment'])); //This makes sure they did not leave any fields blank if (!$_POST['username'] | !$_POST['comment'] ) { die('You did not complete all of the required fields'); }   // enter the comment to the database   $sql = mysql_query ("INSERT INTO comments (id,comments) VALUES ('0','".$comment."')");   echo 'Your comment has been entered successfully!'; } else {   // POST data wasnt entered, so display the comments and comment form   // view comments from database   $sql = mysql_query ("SELECT * FROM comments");   while ($row = mysql_fetch_array ($sql)) {     echo $row['comments'].'<br />';   }  } ?>     <form name= comments action="commentsnew.php" method="post">   Comments:<br /> <tr><td>Username:</td><td>   <input type="text" name="username" maxlength="60">   </td></tr><br />   <textarea name="comment" cols="40" rows="7"></textarea> <input type="submit" name="submit" value="SUBMIT">   </form> <a href=members.php>Click Here to go to the members page</a> </body></html> Quote Link to comment https://forums.phpfreaks.com/topic/198269-the-wall-feature/#findComment-1042133 Share on other sites More sharing options...
Ken2k7 Posted April 15, 2010 Share Posted April 15, 2010 I'm not sure how you want us to help without providing the necessary information. Where is the username stored? What's the table layout? Quote Link to comment https://forums.phpfreaks.com/topic/198269-the-wall-feature/#findComment-1042137 Share on other sites More sharing options...
heyhey01 Posted April 15, 2010 Author Share Posted April 15, 2010 I'm not sure how you want us to help without providing the necessary information. Where is the username stored? What's the table layout? username is stored in the comments table. By table layout did u mean the tables of the database? Quote Link to comment https://forums.phpfreaks.com/topic/198269-the-wall-feature/#findComment-1042152 Share on other sites More sharing options...
heyhey01 Posted April 15, 2010 Author Share Posted April 15, 2010 username is also in members table there is a forgin key linking members to comments table Quote Link to comment https://forums.phpfreaks.com/topic/198269-the-wall-feature/#findComment-1042163 Share on other sites More sharing options...
Ken2k7 Posted April 15, 2010 Share Posted April 15, 2010 Then we have a dilemma. Â $sql = mysql_query ("INSERT INTO comments (id,comments) VALUES ('0','".$comment."')"); ^ You never insert the username so ... where is it? Quote Link to comment https://forums.phpfreaks.com/topic/198269-the-wall-feature/#findComment-1042165 Share on other sites More sharing options...
heyhey01 Posted April 15, 2010 Author Share Posted April 15, 2010 Then we have a dilemma. Â $sql = mysql_query ("INSERT INTO comments (id,comments) VALUES ('0','".$comment."')"); ^ You never insert the username so ... where is it? This is what i got now but it just gives a parse error on that line $sql = mysql_query ("INSERT INTO comments (id,comments,username) VALUES ('0','".$comment."', '".$username."')"); Quote Link to comment https://forums.phpfreaks.com/topic/198269-the-wall-feature/#findComment-1042171 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.