We help IT Professionals succeed at work.

How to pass URL parameters without using get or post

alateos
alateos asked
on
517 Views
Last Modified: 2007-11-27
Hi,
I'm trying to pass a parameter from one page to another using a hyperlink.

Here's a snippet of the passing page:

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td><a href=poo.php?" . $row['id'] . ">" . $row['id'] . "</td>";
  echo "<td>" . $row['name'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

How can I retrieve the id variable from poo.php?
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2004

Commented:
You would need to use $_SERVER['REQUEST_URI']. However, it's probably better to do:

echo '<td><a href="poo.php?id=' . $row['id'] . '>' . $row['id'] . '</a></td>';

Then, in poo.php, you can use

$_GET['id']
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Commented:
@Zyloch
Hey, are you trying to prevent me from getting 1000k? ;-P
CERTIFIED EXPERT
Top Expert 2004

Commented:
Heh, never :P You're getting close!

Author

Commented:
none of these methods are working for me
CERTIFIED EXPERT
Top Expert 2004

Commented:
Is there any error message? What code do you have?

Author

Commented:
here's database.php:
<html>


<?php
$con = mysql_connect("localhost","","l");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
else

mysql_select_db("people", $con);



$sql = "select * from management";
$result = mysql_query($sql);

echo "<table border='1'>
<tr>
<th>ID</th>
<th>Name</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td><a href=poo.php?" . $row['id'] . ">" . $row['id'] . "</a></td>";
  echo "<td>" . $row['name'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

mysql_close($con);
?>
</html>


and here's poo.php:

<html>


<?php
$con = mysql_connect("localhost","root","castel");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
else

mysql_select_db("people", $con);

$id = $_GET['id'];

echo $id;


$sql = "select * from management where id = " . id;
$result = mysql_query($sql);


mysql_close($con);
?>


</html>

Commented:
Ah, it's your turn to pick up the poinks anyway. I get the feeling we're working shift duties here.

I'm getting close indeed, but no cigar yet :)

Anyway, you could use a session alateos,

put this at the top of all the involved php pages (right under <?php )

session_start();

then if you want to set a var in the session, use this:

$_SESSION['id'] = $row['id'];

in poo.php retrieve it like this:

$id = $_SESSION['id'];

Commented:
Hi alateos,

There are ways of doing what you want with something that looks like a directory path and then using mod rewrite to translate part of the path into variables. This method still ends up being gets at the script level but the requestor doesnt see it.

The other way to do it would be by putting data in the cookie to direct the visitor after the request arives.

Which way do you think would work best for you?

Tom

Author

Commented:
yeah but i'm trying to do it without a session.
In asp and jsp this can be done easily... is it not possible in php?

Author

Commented:
I don't get it... if I click on that link it will send me to poo.php with the value of the id. Why can't i just retrieve that URL variable?

Commented:
did you name it? In other words did you put id= before it?

THen $id = $_GET['id']

should work for sure...
CERTIFIED EXPERT
Top Expert 2004

Commented:
Nah, it's yours this time. I'm busy trying to figure out this other problem with finding the intersection between two points or something like that :D [I'm just too lazy to read through the comments lol]

Commented:
Ah, yeah I saw it... interesting one. I'll subscribe to it and will await your solution... Keep your eye on this one though 'cause I'm going to bed soon...

Author

Commented:
sorry for the trouble guys... i missed the first part where I had to name the variable in the URL link. It's working fine now. Though I have another question. This is behaving like a GET. Is there any way I can pass the parameters through the URL without showing them, like in a POST fashion?

Commented:
You could use cURL for that.
http://php.net/curl

It will not be easy though...

Commented:
Btw, your grading made me a 'Genius' at PHP. Thank you for that :)

Author

Commented:
My pleasure :)
and.. thanks for your help

Commented:
You're welcome :)

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.