I have a problem with $_GET. When I click the submit button it doesn’t read the "id" which came from my first page of php. This is the link where the value of id came from <?php echo $content."<p><a href='post.php?id=$pid'>Comment.</a>"?></p> but when I try to to run this echo $_GET['id']; its working at it shows that it has value.
<?php
if (isset($_GET['id'])) {
$c = $_GET['id'];
}
mysql_connect("localhost","root","");
mysql_select_db("blog");
?>
<html>
<head>
<body background="u.jpg">
<center>
<a href="register.php"><img src="1.jpg" width="100" height="50"/></a>
<a href="login.php"><img src="2.jpg" width="100" height="50"/></a>
<a href="index.php"><img src="3.jpg" width="100" height="50"/></a>
</center>
<center>
<title>Pinoy Blog</title>
</head>
<?php
if(isset($_POST['submit']))
{
$content = $_POST['content'];
mysql_query("INSERT INTO comment (comment,p_id) VALUE('$content','$c')");
echo '<a href="index.php">span style="font-size:26px;"><strong><span style="font-family: verdana, geneva, sans-serif; ">Success! Tignan ang post. </span></strong></span>.</a>
|| <a href="post.php">Magpost ulit? Click mo to.</a>';
}else{
?>
<form action='post.php' method='post'>
<span style="font-size:26px;"><strong><span style="font-family: verdana, geneva, sans-serif; ">Comment: </span></strong></span>
<textarea name='content' ></textarea><br />
<input type='submit' name='submit' value='POST!'/>
</form>
<?php
}
?>
<center>
</body>
</html>
1) When you are coming from first page to second page with link then it’s called query string & you will get it in $_GET[‘id’]
2) But now you are on second page & click on submit button it means it is new http request which doesn’t carry $_GET values from previous http request. so you need store $_GET[‘id’] into second page as hidden form field.
Change your php code as below
Now take one hidden field in your form.
Note: $_REQUEST default contains the contents of $_GET, $_POST and $_COOKIE