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
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.
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");
Ok. For each post, pull the data from the db for that particular post(passing the post_id). Then echo the resulting query.
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:
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.
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
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
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.
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.
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