Herra Posted May 7, 2011 Share Posted May 7, 2011 Hello, I'm trying to create a simple php blog thing, and I can't get the commenting to work.. blog.php?id=2 On that page, there is a form what is used to comment, it goes to send.php That php has this query in it: $yhteys = mysql_connect('10.5.49.32', '09A_user', 'pass'); mysql_select_db('09A_Jere', $yhteys); mysql_query("INSERT INTO `Blog_kommentit` (`kayttajat` , `kommentti` , `kirjid` ) VALUES ('$kayttajat', '$kommentti', '$id')") or die(mysql_error())$sql = "SELECT * FROM Blog_kommentit WHERE kirjid='$id' ORDER BY id";; mysql_close($yhteys); header('Location: ' . $_SERVER['HTTP_REFERER']); How can I make the $id to be previous pages id (2)? This shouldn't be anything hard and I'm kinda amazed why I am stuck in this, any help will be appreciated. If I just put $id I get this error: Cannot add or update a child row: a foreign key constraint fails (`09A_Jere/Blog_kommentit`, CONSTRAINT `kommentti_kirjoitus` FOREIGN KEY (`kirjid`) REFERENCES `Blog_kirjoitukset` (`id`)) Here is how my database works: (Kayttajat = username, kommentti = comment) Quote Link to comment https://forums.phpfreaks.com/topic/235767-problem-with-simple-commenting-script/ Share on other sites More sharing options...
violinrocker Posted May 7, 2011 Share Posted May 7, 2011 you can try ummm.... $_GET[id] on your send.php for your id and then on your blog.php's form do something like <form action="send.php?id=<? echo "$_GET[id]"; ?>" method="post"> that way... it sends it to send.php with the id and you can use $_GET[id] once you are in send.php Quote Link to comment https://forums.phpfreaks.com/topic/235767-problem-with-simple-commenting-script/#findComment-1211900 Share on other sites More sharing options...
Herra Posted May 7, 2011 Author Share Posted May 7, 2011 you can try ummm.... $_GET[id] on your send.php for your id and then on your blog.php's form do something like <form action="send.php?id=<? echo "$_GET[id]"; ?>" method="post"> that way... it sends it to send.php with the id and you can use $_GET[id] once you are in send.php Wow thanks, that did work after some tweaking! $id = $_GET['id']; mysql_query("INSERT INTO Blog_kommentit (kayttajat , kommentti , kirjid) VALUES ('$kayttajat', '$kommentti', '$id')") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/235767-problem-with-simple-commenting-script/#findComment-1211908 Share on other sites More sharing options...
PaulRyan Posted May 7, 2011 Share Posted May 7, 2011 Sanitize the $_GET['id'] also, use intval or something Regards, PaulRyan. Quote Link to comment https://forums.phpfreaks.com/topic/235767-problem-with-simple-commenting-script/#findComment-1211934 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.