dyablo61987
New member
I'm developing an application, but im stuck at the comment. I have a blog type of thing set up, but everything is working except the comments. I can add comments, but they are not added to the posts.
My question is how can i make it so when i post the comment it posts on the proper post, in other words i need the comment to automatically fill in the proper 'id' field so it adds to the proper post.
below is the code that i have so far, its a big sloppy, and i need some more security but that comes at a later time for now i just need
<?php
require_once("config.php");
$id = intval($_REQUEST["id"]);
$sql = "SELECT title FROM updates WHERE id = $id";
$result = mysql_query($sql, $connection) or die(mysql_error());
if (mysql_num_rows($result) != 0) {
header("Location: index.php");
exit;
}
$name = mysql_escape_string(strip_tags($_REQUEST["name"]));
$email = ($_REQUEST["email"]);
$comment = mysql_escape_string(strip_tags($_REQUEST["comment"]));
$comment = nl2br($comment);
$sql="INSERT INTO comments (name, email, comment, id)
VALUES
('$_POST[name]','$_POST','$_POST[comment]','$_POST[id]')";
if (!mysql_query($sql,$connection))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
?>
Thats the code that process the comments and updates it.
<form method="POST" action="comment.php">
<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2"><input type="hidden" name="id" value="'$id"></td>
</tr>
<tr>
<td width="135">Name</td>
<td width="365"><label>
<input type="text" name="name" id="name">
</label></td>
</tr>
<tr>
<td>Email</td>
<td><label>
<input type="text" name="email" id="email">
</label></td>
</tr>
<tr>
<td>Comments</td>
<td><label>
<textarea name="comment" id="comment" cols="45" rows="5"></textarea>
</label></td>
</tr>
<tr>
<td colspan="2"><label>
<input type="submit" name="submit" id="submit" value="Post Comment">
</label></td>
</tr>
</table>
</form>
and thats the script for the form were the people insert the comments
Any help would be gladly appreciated!!
My question is how can i make it so when i post the comment it posts on the proper post, in other words i need the comment to automatically fill in the proper 'id' field so it adds to the proper post.
below is the code that i have so far, its a big sloppy, and i need some more security but that comes at a later time for now i just need
<?php
require_once("config.php");
$id = intval($_REQUEST["id"]);
$sql = "SELECT title FROM updates WHERE id = $id";
$result = mysql_query($sql, $connection) or die(mysql_error());
if (mysql_num_rows($result) != 0) {
header("Location: index.php");
exit;
}
$name = mysql_escape_string(strip_tags($_REQUEST["name"]));
$email = ($_REQUEST["email"]);
$comment = mysql_escape_string(strip_tags($_REQUEST["comment"]));
$comment = nl2br($comment);
$sql="INSERT INTO comments (name, email, comment, id)
VALUES
('$_POST[name]','$_POST','$_POST[comment]','$_POST[id]')";
if (!mysql_query($sql,$connection))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
?>
Thats the code that process the comments and updates it.
<form method="POST" action="comment.php">
<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2"><input type="hidden" name="id" value="'$id"></td>
</tr>
<tr>
<td width="135">Name</td>
<td width="365"><label>
<input type="text" name="name" id="name">
</label></td>
</tr>
<tr>
<td>Email</td>
<td><label>
<input type="text" name="email" id="email">
</label></td>
</tr>
<tr>
<td>Comments</td>
<td><label>
<textarea name="comment" id="comment" cols="45" rows="5"></textarea>
</label></td>
</tr>
<tr>
<td colspan="2"><label>
<input type="submit" name="submit" id="submit" value="Post Comment">
</label></td>
</tr>
</table>
</form>
and thats the script for the form were the people insert the comments
Any help would be gladly appreciated!!