We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,267 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Passing a value via href - php

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 :)

7
Contributors
8
Replies
3 Years
Discussion Span
2 Years Ago
Last Updated
20
Views
Binary
Newbie Poster
3 posts since Apr 2006
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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.

Ezzaral
null
Moderator
16,111 posts since May 2007
Reputation Points: 3,292
Solved Threads: 873
Skill Endorsements: 28

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 :)

Binary
Newbie Poster
3 posts since Apr 2006
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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

MitkOK
Junior Poster
142 posts since Jul 2007
Reputation Points: 59
Solved Threads: 12
Skill Endorsements: 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 :)

Binary
Newbie Poster
3 posts since Apr 2006
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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.

Ezzaral
null
Moderator
16,111 posts since May 2007
Reputation Points: 3,292
Solved Threads: 873
Skill Endorsements: 28

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

maheen123
Newbie Poster
13 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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.

darrell1226
Newbie Poster
1 post since Dec 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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

almostbob
Nearly a Senior Poster
3,280 posts since Jan 2009
Reputation Points: 585
Solved Threads: 399
Skill Endorsements: 7

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0939 seconds using 2.69MB