Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 20th, 2005, 02:19 AM
Registered User
 
Join Date: Jan 2005
Location: Bangalore, Karnataka, India.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
Reply With Quote
  #2 (permalink)  
Old January 20th, 2005, 03:08 AM
Friend of Wrox
 
Join Date: Oct 2003
Location: Cochin, Kerala, India.
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madhukp
Default

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.
Reply With Quote
  #3 (permalink)  
Old January 20th, 2005, 04:31 AM
Registered User
 
Join Date: Jan 2005
Location: Bangalore, Karnataka, India.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #4 (permalink)  
Old January 20th, 2005, 05:15 AM
Friend of Wrox
 
Join Date: Oct 2003
Location: Cochin, Kerala, India.
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madhukp
Default

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.
Reply With Quote
  #5 (permalink)  
Old January 20th, 2005, 06:08 AM
Registered User
 
Join Date: Jan 2005
Location: Bangalore, Karnataka, India.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
Reply With Quote
  #6 (permalink)  
Old January 20th, 2005, 06:27 AM
Friend of Wrox
 
Join Date: Oct 2003
Location: Cochin, Kerala, India.
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madhukp
Default

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.
Reply With Quote
  #7 (permalink)  
Old January 20th, 2005, 06:42 AM
Registered User
 
Join Date: Jan 2005
Location: Bangalore, Karnataka, India.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
Reply With Quote
  #8 (permalink)  
Old April 9th, 2006, 08:47 AM
Registered User
 
Join Date: Apr 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
  #9 (permalink)  
Old April 9th, 2006, 12:31 PM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

What does the following output?

Code:
<?php
   echo "<pre>";
   var_dump($_REQUEST);
   echo "</pre>";
?>
How about a link to a phpinfo() page?

<?php phpinfo(); ?>

Regards,
Rich

--
Author,
Beginning CSS: Cascading Style Sheets For Web Design
CSS Instant Results

http://www.catb.org/~esr/faqs/smart-questions.html
Reply With Quote
  #10 (permalink)  
Old April 9th, 2006, 11:27 PM
Registered User
 
Join Date: Apr 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing javascript variable to html or php ashraf_gawdat Javascript How-To 3 July 12th, 2006 02:48 PM
Passing PHP variables to javascript wfrisch Pro PHP 10 April 5th, 2005 05:13 AM
Passing Variables from PHP to PHP brian3166 PHP How-To 4 January 31st, 2005 12:44 AM
PHP passing variables to .swf file Ashleek007 Flash (all versions) 4 December 15th, 2004 09:38 PM
passing variables from PHP to Perl joconnor Beginning PHP 4 July 21st, 2004 08:13 AM



All times are GMT -4. The time now is 10:53 PM.


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