Thank you for that. I thought you could but I just wanted to make sure.
Can you have a variable within a form action? On my readmore.php I have added a “comment” box. I would like it so that when people commented it would link it to that particular story. I read that a simple way to do this was to give the comments a parent id that related to each story number. That way each time a story was called up the related comments would also be called up with it.
What I have done is created a table called comments with 4 columns (C_Id, parent, comment, screen_name).The C_Id is the primary key and is auto increment. When a user enters a comment on a particular story I would like the parent to be the same as the P_Id on the readmore page. I thought the easiest way to do this would be to copy the line of code you have already helped me with for the index page Read more and add it to my form action=
This is the read more code i came up with.
[php]
BanterDonkey | Read More
<?php
$con = mysql_connect("host","user","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db(“database”) or die(mysql_error());
$storyid = $_GET[“storyid”]; // gets storyid from the url
// Assuming you’ve already connected to your database:
$result = mysql_query(“SELECT * FROM banter WHERE P_Id = ‘$storyid’”);
// Replace “table_name” with the name of your table.
// And replace “row_primary” with the name of the column you marked as the primary key.
while ($row = mysql_fetch_array($result)) {
echo “
”;
echo “
{$row[‘P_Id’]}
”; // Replace “column_one” with the name of your first column.
echo “
{$row[‘story’]}
”; // Replace “column_two” with the name of your second column.
echo “
{$row[‘screen_name’]}
”; // Replace “column_three” with the name of your third column.
echo “
”;
}
mysql_close($con);
?>
// up to here works fine. My problem is the next line
Please enter your screen name. If you currently do not have a screen name you can register for one here
Please enter your password. Forgotten your password? Click here
[/php]
However when i click submit it doesn’t grab the P_Id it just appears exactly as this www.banterdonkey.com/comment.php?storyid=$row[P_Id] - its not adding the variable.
Is there a better way of carrying that P_Id forward? For completeness here is the code for comment.php
[php]<?php
//This makes sure they did not leave any fields blank
if (!$_POST[‘comment’] || !$_POST[‘screen_name’] ) {
die('You did not complete all of the required fields');
}
$storyid = $_GET[“storyid”];
// Connection to database
$con = mysql_connect(“host”,“user”,“pass”);
if (!$con)
{
die('Could not connect: ’ . mysql_error());
}
mysql_select_db(“database”) or die(mysql_error());
// Limit the result to only one row, because there should only be one user with that screen_name:
$result = mysql_query(“SELECT * FROM login WHERE screen_name=’$_POST[screen_name]donkey’ LIMIT 0,1”);
// Check to see if it actually got something, if so, continue on:
if(mysql_num_rows($result) != 0) {
// Fetch the row and drop it into an array:
$row = mysql_fetch_array($result);
// Assuming that the password is entered in the database already, :
if ($_POST[‘pass’] == $row[‘pass’]) {
// Password is correct
$sql=“INSERT INTO comments (parent, comment, screen_name)
VALUES
(’$_POST[$storyid]’, ‘$_POST[comment]’,’$_POST[screen_name]’)”;
if (!mysql_query($sql,$con))
{
die('Error: ’ . mysql_error());
}
echo “Thank You for posting”;
mysql_close($con);
}
else {
// Password is incorrect
echo “Your password does not match our records”;
}
}
else {
echo “Your username does not exist”;
}
?>[/php]
Many thanks,
Sam