 |
| PHP How-To Post your "How do I do this with PHP?" questions here. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

January 20th, 2005, 02:19 AM
|
|
Registered User
|
|
Join Date: Jan 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Passing variables from HTML to php
Hi, I'm new to PHP and to this forum.
I'd like to clear one doubt.
I've two php pages (page1.php, page2.php). In page1.php i'am trying to access a database and create an html table for the output with each row having an href anchor tag. now on clicking the link page2.php should be loaded with a value passed from page1.php. sample of how i've coded is as follows:
<?php
database accessing...
print("<table>);
while (-condition-)
{
print("<tr>");
print("<td>");
print(<a href='page2.php?sid=$curr_row[0]'>Go to Page 2</a>");
print("</td>");
print("</tr>");
}
print("</table>");
Now the html generated is as follows:
<table>
<tr>
<td>
<a href='page2.php?sid=14'>Go to Page 2</a>
</td>
</tr>
<tr>
<td>
<a href='page2.php?sid=15'>Go to Page 2</a>
</td>
</tr>
<tr>
<td>
<a href='page2.php?sid=16'>Go to Page 2</a>
</td>
</tr>
On running, this loads page2.php but i'm not able to receive the value of sid in page2.php I'm not using any form or submit button. Is there any way to get the value of sid directly from href link?
i tried with $_GET['sid'] and $_POST['sid'], but both didn't work.
Any help is most valuable.
thanks and regards
Manu
|
|

January 20th, 2005, 03:08 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
You have to use $_GET["sid"] to get the value of sid.
You cannot use $sid to get the values. This was possible only in PHP versions before 4.2. You may however have this feature by changing php.ini file. You need to change the setting register_globals = on. But this is not recommended as there are some very serious security problems when you do this.
If you are using a version before 4.3, $HTTP_GET_VARS["sid"] will give you the value.
|
|

January 20th, 2005, 04:31 AM
|
|
Registered User
|
|
Join Date: Jan 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Dear Madhu,
Thank you for the reply.
I've tried both $_GET["sid"] and $_POST["sid"] in page2.php
--page2.php--
<?php
$var1 = $_GET["sid"];
$var2 = $_POST["sid"];
echo $var1;
echo $var2;
?>
this time nothing is printed in the browser, but if put var1 and var2 in the echo statement in quotes browser simply prints - $var1 $var2
I'm not able to fetch the value in sid i passed from page1.php
i've tried <form action='page2.php' method='post'> also in page1.php
That also didn't work. What could be the reason.
My intension is to create a page like the one in any email inbox. On clicking the "subject" link it should show the detailed page.
please advise.
Thanks and regards
Manu
|
|

January 20th, 2005, 05:15 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Have you tried $HTTP_GET_VARS["sid"] ? perhaps you may be using an old version of PHP.
Also, please let me know the version of PHP.
|
|

January 20th, 2005, 06:08 AM
|
|
Registered User
|
|
Join Date: Jan 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hai Madhu,
I'm using PHP5/MySQL4/IIS5 on WinXP.
How about the code that i've quoted. Normally it should work! ney?
is it necessary that we should use the <a href= ...?sid=..> </a> within a <form> to access the value of sid on the target page.
|
|

January 20th, 2005, 06:27 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
No need of putting anchor tag in a form.
First validate the HTML page where the link falls. There may be some extra quotes etc.
Just run
<?php
call phpinfo();
?>
and check whether results are getting.
If the above 2 steps did not produce any result, it may be because of installation problem. OPen IIS, go to properties of default web site, click home directory tab. Click configuration. In the app mappings, check whether .php is there. If yes, double-click it to edit it. check whether the permitted verbs include get and post.
|
|

January 20th, 2005, 06:42 AM
|
|
Registered User
|
|
Join Date: Jan 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hai Madhu,
I am able to run php code succesfully.
I'am able to query the database and flush the results into an html table rows. What i want is on clicking any row (in which i've given the <a href=...> it should pass some value to the next php page where in i want to process some other query based on this value. everything in page2.php except the value of the variable is displayed in the browser.
|
|

April 9th, 2006, 08:47 AM
|
|
Registered User
|
|
Join Date: Apr 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hi, i am new to php and i too have the same problem that Mr.manunair faced. can any one help me.
|
|

April 9th, 2006, 11:27 PM
|
|
Registered User
|
|
Join Date: Apr 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hi richard,
still i dont get the value. The out for the code is:
array(2) {
["code"]=>
string(0) ""
["PHPSESSID"]=>
string(32) "0c7b3a09a0809b25fae377f41b4a6849"
}
below is my coding:
print "<td width=\"28%\" align=\"right\">";
print"<a href='contra.php?code='".rawurlencode($data[$i]->Code)."'''>";
print "<img src='122.gif' border=0 >";
print"</a>";
print"</td>";
i am geting the data from the database.
|
|
 |