onthespot Posted July 6, 2009 Share Posted July 6, 2009 Hey. I have made a table called comments, which has 4 fields (fromuser, touser, comment, commentdate). I have then added a form on each user profile for a comment to be added. <form action="comment.php" method="POST"> <p>Comment<input type="text" name="comment"> <input type="submit" name="submit" value="Add Comment"> </form> I have then made the following comment.php include("include/sesh.php"); $from=$_SESSION['username']; $to=$_GET['user']; $comment=$_POST['comment']; function addComment($from, $to, $comment){ $query="INSERT INTO comments VALUES ('$to','$from','$comment', now())"); return mysql_query($query); } The include file has the session starter, and has the username session there. The get I am using is based up there being ?user=username in the URL, on the initial page the form was on. This isn't working, i think i have just got it completely wrong, would appreciate some guidance here. Link to comment https://forums.phpfreaks.com/topic/164948-solved-user-profile-comments/ Share on other sites More sharing options...
elis Posted July 6, 2009 Share Posted July 6, 2009 It looks like you've defined the function to add the comment into the database, but aren't actually using the function anywhere. (Unless it's used later on in your script.) Link to comment https://forums.phpfreaks.com/topic/164948-solved-user-profile-comments/#findComment-869786 Share on other sites More sharing options...
onthespot Posted July 6, 2009 Author Share Posted July 6, 2009 Do i actually need the function? And I need to POST and GET on the initial form. POST the comment, but GET the username from the URL. Any ideas? Whats request for? Link to comment https://forums.phpfreaks.com/topic/164948-solved-user-profile-comments/#findComment-869790 Share on other sites More sharing options...
elis Posted July 6, 2009 Share Posted July 6, 2009 <?php include("include/sesh.php"); $from=$_SESSION['username']; $to=$_GET['user']; $comment=$_POST['comment']; $query="INSERT INTO comments VALUES ('$to','$from','$comment', now())"); ?> This should work. I don't know the entire specifics of your code but (ideally) it should work. You need to sanitize your $_GET and $_POSTs to aid in preventing attacks on your site. You should also probably use an id in $_GET instead of the actual username, so that if a username contains spaces or other peculiar characters, or just for matching sake, it's more uniformed. You need to also pass your username to the form or use a hidden post. <form action="comment.php?user=<?php=$_GET['user']?>" method="POST"> <p>Comment<input type="text" name="comment"> <input type="submit" name="submit" value="Add Comment"> </form> Link to comment https://forums.phpfreaks.com/topic/164948-solved-user-profile-comments/#findComment-869802 Share on other sites More sharing options...
onthespot Posted July 6, 2009 Author Share Posted July 6, 2009 Hey, I tried that, but I got a Parse error on the line where you were passing the user over. <form action="comment.php?user=<?php=$_GET['user']?>" method="POST"> That line! Any ideas? Oh and do you have a link where I can learn more about these attacks? Link to comment https://forums.phpfreaks.com/topic/164948-solved-user-profile-comments/#findComment-869810 Share on other sites More sharing options...
elis Posted July 6, 2009 Share Posted July 6, 2009 Try <form action="comment.php?user=<?php echo $_GET['user']; ?>" method="POST"> And for the attacks: http://en.wikipedia.org/wiki/SQL_injection Link to comment https://forums.phpfreaks.com/topic/164948-solved-user-profile-comments/#findComment-869816 Share on other sites More sharing options...
onthespot Posted July 6, 2009 Author Share Posted July 6, 2009 Well got rid of the error, but got a new one on the $query line, its just not having it. Thanks for the wikipedia page, will take a look Link to comment https://forums.phpfreaks.com/topic/164948-solved-user-profile-comments/#findComment-869822 Share on other sites More sharing options...
onthespot Posted July 6, 2009 Author Share Posted July 6, 2009 OK not getting errors, but the database not updating now! dammm! Link to comment https://forums.phpfreaks.com/topic/164948-solved-user-profile-comments/#findComment-869830 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.