Jump to content

[SOLVED] User profile comments


onthespot

Recommended Posts

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

<?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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.