I’m currently trying to expand my basic news feature so that comments can be added.
My current attempt is to fetch the news and add a simple text box under each where you can type in some text and click a button so that the comment will end up in a seperate table in the database(not in same table as news). Comments will however have the same id as the news post and will therefor be able to be linked appropriately. Currently I’m setting the comment buttons name to the id of the news post it belongs to, but my problem is how to then check whether the comment was posted since the id can be any number and I can’t know it’s value..
Here’s my current code to display news and the text field and button:
$GetNews = mysql_query("SELECT * FROM News ORDER BY id DESC") or die(mysql_error());
while ($row = mysql_fetch_assoc($GetNews))
{
//get data
$news = $row['news'];
$id = $row['id'];
echo "<br/>".$news."<form name='comment' method='POST'><input type='text'>
<input type='submit' name='".$id."' value='comment'></form><hr/>";
}
And here’s the code with which I’m trying to check if a comment (and which) was posted:
if($_POST['--- here i would need to know the ids value ---'])
{
//create new comment with id = buttons id....
}
Could anybody give me any tips or perhaps show me in the right direction. Should i try using GET instead or is this the wrong approach altogether?
I’ve found amazingly little documentation on the topic and can’t find any tutorials.
Any help, ideas, tips, links etc would be greatly appreciated 🙂
just put the value to value=’$id:comment’ and put the name as “comment”
and at the php end do this
$arr = explode(“:”,$_POST[“name”]);
$id = $arr[0];
or use hidden fields