Beginning PHPBeginning-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 .
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
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.
<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
Perhaps a snippet of code will help us to better understand what is going on.
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:
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.