Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP 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 Display Modes
  #1 (permalink)  
Old October 17th, 2003, 01:24 PM
Registered User
 
Join Date: Oct 2003
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default passing data to php pgm

Sorry if I am asking the wrong Q for this forum. I want to use the GET method to pass 2 fields to a 2nd PHP script using HTML anchor,
via a query string, but I don't know how enter the fields to get them "evaluated". THe 2nd program keeps outputing the variable name and not the data in the variable.
Thanks for any help
Maureen

Reply With Quote
  #2 (permalink)  
Old October 17th, 2003, 01:39 PM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm not quite sure I follow you. Can you be more specific, perhaps show us some of your code or describe the process again?

When you pass variables via GET to a PHP script, those variables are available within PHP in the $_GET array.

For example, the URL for this topic ends in the query string: ?TOPIC_ID=5400

If this were a PHP script, you could access the value 5400 via $_GET['TOPIC_ID'].

There's lots of documentation in the PHP manual about this; in fact, it's in all the beginner tutorials.
  http://www.php.net/manual




http://p2p.wrox.com/topic.asp?TOPIC_ID=5400

Take care,

Nik
http://www.bigaction.org/
Reply With Quote
  #3 (permalink)  
Old October 17th, 2003, 01:53 PM
Registered User
 
Join Date: Oct 2003
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, thank you for the reply. I am accessing the information using
$_GET[dataname] but the problem is that I did not pass this using
HTML's form I directly coded that data into the URL of the anchor tag. <a href=http:// bla bla bla?date=$date&time=$time>
When this link is pressed I go to the url of the new program and
i am able to get $_GET[date] but it is equal to "$date" rather then the value of $date which would be 2003/10/17. So it might be an HTML question and not appropriate for this site.

Reply With Quote
  #4 (permalink)  
Old October 17th, 2003, 02:08 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 5 Times in 5 Posts
Default

Hi Maureen,
<a href="http:// bla bla bla?date=$date&time=$time">
Is the correct syntax.

When you access this in PHP you should be quoting the array indice $_GET["date"] or $_GET['date'] ..  the problem with not quoting the indice is PHP first assumes this is a defined constant and does not consider this a string unless no defined constant could be found!  PHP would issue an error under error_reporting = E_ALL.  I am not sure if there is a defined constant named 'date' but if there is this may be why you are having difficulty.

Also I'm not sure if I understand what you're getting at:
<a href="http:// bla bla bla?date=$date&time=$time#name">
                                    \----------------------/\----/
                                       url embedded html anchor
                                       arguments

Perhaps a snippet of code will help us to better understand what is going on.

: )
Rich

:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
Reply With Quote
  #5 (permalink)  
Old October 17th, 2003, 02:58 PM
Registered User
 
Join Date: Oct 2003
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I added an x to the variable names so that there will be no
conflict with any reserved words called date and time.

The variables are set to a date and time before being passed:
<?
    $datex = $_POST[programDate];
        $timex = $_POST[programTime];
  ?>
and I printed them out in pgm 1 to make sure they contained what I wanted
This is the anchor link in program 1:

<p><a href='show_addProgramAsana.php?datex=$datex&timex= $timex'>Identify Asanas</a></p>

Now this is the code in the 2nd pgm where I try to access the info:

<?

    print "$_GET[datex] = date and $_GET[timex] = time";
    include("yogaconnect.inc");
?>
 this is what is output:
$datex = date and $timex = time



Reply With Quote
  #6 (permalink)  
Old October 17th, 2003, 03:03 PM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Looking at your HTML, it seems that you're trying to use PHP variables while not within <?php and ?> delimiter tags.


Take care,

Nik
http://www.bigaction.org/
Reply With Quote
  #7 (permalink)  
Old October 17th, 2003, 03:19 PM
Registered User
 
Join Date: Oct 2003
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You are right nikolai, perhaps there is no way to really do this.
I put <? ?> around my variables, but now I get:
= date and = time
so I'll just rethink this and add a form with a hidden field.
Thanks

Reply With Quote
  #8 (permalink)  
Old October 17th, 2003, 03:26 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 5 Times in 5 Posts
Default

For the sake of understandability and adhearing to programming standards you should still quote your indices!

In a developement environment its extremely helpful to have error_reporting set to E_ALL, it helps catch many blunders. It tells you when a variable is not defined (When you may want one defined!). It also helps to tighten up the flow of a script since everything is defined very strict and explicitly there is less room for security exploitations. So that being said I strongly encourage you to move in that direction. Its troubleshooting & security benefits outweigh its nuisances.

$datex = $_POST['programDate'];
$timex = $_POST['programTime'];

This is acceptable because it is contained inside of quotes, e.g. the indices are treated like strings first and not constants:
print "$_GET[datex] = date and $_GET[timex] = time";

I would still prefer to do this instead:
print "{$_GET['datex']} = date and {$_GET['timex']} = time";

Also there is no predefined constant named date.

Quote:
quote:
You are right nikolai, perhaps there is no way to really do this.
I put <? ?> around my variables, but now I get:
= date and = time
so I'll just rethink this and add a form with a hidden field.
It can be done!

<p><a href='show_addProgramAsana.php?datex=<?php echo $_POST['programDate'];?>&timex=<?php echo $_POST['programTime']; ?>'>Identify Asanas</a></p>

: )
Rich




:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
Reply With Quote
  #9 (permalink)  
Old October 17th, 2003, 03:40 PM
Registered User
 
Join Date: Oct 2003
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It can be done!

<p><a href='show_addProgramAsana.php?datex=<?php echo $_POST['programDate'];?>&timex=<?php echo $_POST['programTime']; ?>'>Identify Asanas</a></p>

: )
Rich

Thanks for the E_ALL advice and the solution. It worked like a charm.
Maureen

Reply With Quote
Reply


Thread Tools
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 data from PHP to Javascript oldBroh Javascript How-To 12 June 12th, 2008 11:12 PM
VS 2003 pgm runs only on development box Ron Howerton Pro VB.NET 2002/2003 4 June 16th, 2006 03:20 PM
Passing data from PHP to Javascript youngj PHP How-To 4 February 22nd, 2006 10:55 PM
passing value from Php to PHP page baby PHP How-To 3 March 31st, 2005 01:13 AM
Passing Variables from PHP to PHP brian3166 PHP How-To 4 January 30th, 2005 11:44 PM



All times are GMT -4. The time now is 06:50 PM.


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