i m a student & new to php i want to pass id from one page to another page using get & post method
but the id can not be passed it shoes the variable in URL instead of value
please can any one help me
Here is the code

Page : view_tanent.php

//$id= $_GET["tanent_id"];
$con= mysql_connect("localhost","root","root");
	die('could not connect: ' . mysql_error());

mysql_select_db("ccs_easyrentcollect", $con);
//$id= $_GET["tanent_id"];
    $result = mysql_query("select * from ccs_tanent");
	//$id= $_GET["tanent_id"];
    $maxColumns = 5;
   echo'<table cellspacing="0" cols="5" bgcolor="#CCCCCC" bordercolor="#993300" border="1" cellpadding="2" width="500px"><tr>';
	echo '<td width="25" align="center"><font color="#CC0099">', "Tanent Name" ,'</font></td>';
	echo '<td width="64" align="center"><font color="#CC0099">' ,"Email ID" ,'</font></td>';
	echo '<td width="20" align="center"><font color="#CC0099">' ,"Contact No" ,'</font></td>';
	echo '<td width="20" align="center">',"",'</td>';
	echo '<td width="20" align="center">',"",'</td>';	
    echo '<table cellspacing="0" cols="5" bgcolor="#CCCCCC" bordercolor="#993300" border="1" cellpadding="4" width="500px"><tr>';
    for ($currentColumn = 0; $data = mysql_fetch_object($result); $currentColumn++) {
      if ($currentColumn = $maxColumns) {
        echo '</tr><tr>';
        $currentColumn = 0;
     //echo   "Tanent Name" ;
//	$id=$_GET["id"];
echo $id;

	   echo '<td width="75" align="center">' . $id. '</td>'; 
      echo '<td width="75" align="center">' . $data->tanent_name . '</td>';
	  echo '<td width="18" align="center">' . $data->email_id . '</td>';
	  echo '<td width="35" align="center">' . $data->contact_no . '</td>';
echo '<td><a href="update_tanent.php?id=$id">',"Edit",'</a></td>';
echo '<td><a href="view_tanent.php?id=$id">',"Delete",'</a></td>';
    echo '</tr></table>';


from this page i want to pass tanent_id to teh another page plz help me

Edited by Poonam Jadav: n/a

5 Years
Discussion Span
Last Post by pzuurveen

echo doesn't print the variable values when using a single quoted string.

$id = 1;
echo "<td>$id</td>"; // output: "<td>1</td>"
echo '<td>$id</td>'; // output: "<td>$id</td>"

there are a number of ways you could get around this issue, one would be to change those two link lines to be like this

echo '<td><a href="update_tanent.php?id=',$id,'">Edit</a></td>';

(for more information, check the php man pages ;)

Edited by |-|x: n/a


thank u very much
but there is an error in another page wich is recievin the value

$con= mysql_connect("localhost","root","root");
	die('could not connect: ' . mysql_error());

mysql_select_db("ccs_easyrentcollect", $con);
$id= $_POST["id"];

$query="select * from ccs_tanent where tanent_id='$id'";

$result=mysql_query($query) or die ("error in query");

if (mysql_num_rows($result)>0)

On the receiving page you need to use

$id = $_GET['id'];

not $_POST as you are not posting the data (you would be if using a form to pass the data) you are sending in a URL and therefore need to use $_GET.


I'm having a similar problem.
My first page is passing an ID value. This is the url of my 2nd page:

This is the code from my 2nd page.

$product = $_GET['id'];
$productquery = "SELECT * FROM productdets WHERE Product_id=".$product;
$row = mysql_query($productquery);

print $row['SeriesName'];

However this code brings back this error: Notice: Undefined index: id
Haven't I already defined 'id'? What am I missing?

Edited by KristopherNixon: added a link


Thank you! I was unaware that had to match.
Now I get the error: Undefined index: Product_id

But it works in my browser.

Thanks for your help.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.