1,105,225 Community Members

Passing a value via href - php

Member Avatar
Binary
Newbie Poster
3 posts since Apr 2006
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I recently started working with PHP, and MySQL. And I have come with a little problem, I have tried a couple of things to solve it and they are not working. Well, basically I am trying to put a link on a page, but that page requires me to pass a value, here's an example below, e.g.

If I am on this page for example

http://www.mypage.com/view.php?prop_id=5

and I want to add a link, that would translate to

<a href="submit_docs.php?prop_id=5 ">Click </a>

How do I accomplish this, how do I pass the php variable "prop_id" to a href link? Can someone shed me some light on this matter? Thanks a lot :)

Member Avatar
Ezzaral
Posting Sage
7,431 posts since May 2007
Reputation Points: 2,714 [?]
Q&As Helped to Solve: 953 [?]
Skill Endorsements: 31 [?]
Moderator
Featured
 
0
 

Um, you do it exactly like you have indicated in your link. I'm not certain what your question is exactly. Are you unsure how to build the link string? Unsure how to retrieve the value in the target page? Please elaborate a bit.

Member Avatar
Binary
Newbie Poster
3 posts since Apr 2006
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Um, you do it exactly like you have indicated in your link. I'm not certain what your question is exactly. Are you unsure how to build the link string? Unsure how to retrieve the value in the target page? Please elaborate a bit.

Yes, I am not sure how to build the link string that would pass the prop_id=[current_id_value] variable. I typed the prop_id=5 as an example, technically it could be any number. I am guessing there is a way to get the variable from the MySQL database, but once I get it, how do it build the link. Thanks again :)

Member Avatar
MitkOK
Junior Poster
142 posts since Jul 2007
Reputation Points: 61 [?]
Q&As Helped to Solve: 13 [?]
Skill Endorsements: 0 [?]
 
0
 

If I am on this page for example

http://www.mypage.com/view.php?prop_id=5

and I want to add a link, that would translate to

<a href="submit_docs.php?prop_id=5 ">Click </a>

How do I accomplish this, how do I pass the php variable "prop_id" to a href link? Can someone shed me some light on this matter? Thanks a lot :)

What do you mean by trabslate ?

If you want to you use prop_id from view.php url in link :

$prop_id = '$_GET[prop_id]';

echo "<a href=\"submit_docs.php?prop_id=".$prop_id."\">Click </a>";

- Mitko Kostov

Member Avatar
Binary
Newbie Poster
3 posts since Apr 2006
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

What do you mean by trabslate ?

If you want to you use prop_id from view.php url in link :

$prop_id = '$_GET[prop_id]';

echo "<a href=\"submit_docs.php?prop_id=".$prop_id."\">Click </a>";

- Mitko Kostov

It works! Thanks a lot Mitko, and everyone who viewed this post :) By using the code:

echo "<a href=\"submit_docs.php?prop_id=".$prop_id."\">Click </a>";

I get the link with the prop_id variable. However I want to point something out, if I try to use for example

$varid_id = '$_GET[prop_id]';

And used $varid_id instead of $prop_id I get an error, In other words, I did not have to declare $prop_id to use it in the link.
Again thanks a lot :)

Member Avatar
Ezzaral
Posting Sage
7,431 posts since May 2007
Reputation Points: 2,714 [?]
Q&As Helped to Solve: 953 [?]
Skill Endorsements: 31 [?]
Moderator
Featured
 
0
 

I get the link with the prop_id variable. However I want to point something out, if I try to use for example

$varid_id = '$_GET[prop_id]';

And used $varid_id instead of $prop_id I get an error, In other words, I did not have to declare $prop_id to use it in the link.
Again thanks a lot :)

He just included that as an example of retrieving prop_id from a GET page request. If prop_id had been passed in via a link, you would get it with that code. If you are generating the prop_id from another source, you wouldn't need to pull it from the $_GET[] array.

Member Avatar
maheen123
Newbie Poster
13 posts since Apr 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Um, you do it exactly like you have indicated in your link. I'm not certain what your question is exactly. Are you unsure how to build the link string? Unsure how to retrieve the value in the target page? Please elaborate a bit.

Hi!
I have the similar prrob as described by Binary . But i want to edit any row value displayed in a form in the form of a table . Now i want to edit a specific field after selecting. But If I put an edit link before each row or whatever , how can i pass the relavent variable values to the called form... I want to know the syntax or in simple words i want to send variables in a link string.
Supoz i have

echo "<td>".$row['lname']."</td>";

now how can i add an edit link to it that will make me able to edit a specfic field. DO i need to add it on row level?
Please help me
Thanks

Member Avatar
darrell1226
Newbie Poster
1 post since Dec 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I have a similar question. I am passing the ?id=%s to the href link. I want to pick up that id number later. How do I retrieve that number so I can use that id to display specific table data on the page? Hope you understand.

Member Avatar
almostbob
Nearly a Senior Poster
3,381 posts since Jan 2009
Reputation Points: 515 [?]
Q&As Helped to Solve: 424 [?]
Skill Endorsements: 14 [?]
 
0
 

as above, the $_GET array contains the parameters passed in the url
to get the value ?id=%s

echo $_GET['id']; 
/* or if the id is being used more often than once assign it as a variable */
$id = $get['id'];
echo $id;
/* do some math */ + $id; // bla bla bla

Hth

referring to $_request, $_post, $_get in the php online manuals may provide useful code samples

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article