hello
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

<?php
//$id= $_GET["tanent_id"];
//$id=$_GET["id"];
$con= mysql_connect("localhost","root","root");
if(!$con)
{
	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"];
	///$tid=mysql_field_name($result,0);
    //$id=$_GET[$tid];
    $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'</tr>';
	 echo'</table>'; 
  
    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"];
$id=$data->tanent_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

Ajayi_2 commented: echo '<td><a href="update_tanent.php?id=$id">',"Edit",'</a></td>'; +0

Recommended Answers

All 9 Replies

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

$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 ;)

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

<?php
			
$con= mysql_connect("localhost","root","root");
if(!$con)
{
	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)
{
	$row=mysql_fetch_object($result);
	
}
?>

what is the error?

I don't think $id= $_POST["id"]; will work since you are passing the value in the url.

take a look at $_Request and HttpQueryString

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:
http://localhost/ProductPresentation/Product_Dets.php?Product_id=2

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?

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

But it works in my browser.
Strange.

Thanks for your help.

if(isset( $_GET['Product_id'])) $product = $_GET['Product_id'];
else echo " no product id";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.