p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   PHP How-To (http://p2p.wrox.com/forumdisplay.php?f=98)
-   -   Passing variables from HTML to php (http://p2p.wrox.com/showthread.php?t=24176)

manunair January 20th, 2005 02:19 AM

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:

database accessing...

while (-condition-)
    print(<a href='page2.php?sid=$curr_row[0]'>Go to Page 2</a>");

Now the html generated is as follows:
     <a href='page2.php?sid=14'>Go to Page 2</a>
     <a href='page2.php?sid=15'>Go to Page 2</a>
     <a href='page2.php?sid=16'>Go to Page 2</a>

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


madhukp January 20th, 2005 03:08 AM

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.

manunair January 20th, 2005 04:31 AM

Dear Madhu,
Thank you for the reply.
I've tried both $_GET["sid"] and $_POST["sid"] in page2.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

madhukp January 20th, 2005 05:15 AM

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.

manunair January 20th, 2005 06:08 AM

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.

madhukp January 20th, 2005 06:27 AM

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
    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.

manunair January 20th, 2005 06:42 AM

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.

nandha_k April 9th, 2006 08:47 AM

hi, i am new to php and i too have the same problem that Mr.manunair faced. can any one help me.

richard.york April 9th, 2006 12:31 PM

What does the following output?


   echo "<pre>";
   echo "</pre>";

How about a link to a phpinfo() page?

<?php phpinfo(); ?>


Beginning CSS: Cascading Style Sheets For Web Design
CSS Instant Results


nandha_k April 9th, 2006 11:27 PM

hi richard,

still i dont get the value. The out for the code is:

array(2) {
  string(0) ""
  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 >";

i am geting the data from the database.

All times are GMT -4. The time now is 01:14 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.