URL Query String Wont Work

Hello,

Yes, I have searched this forum. Yes, I have searched the stickies.

I am new. And undoubtedly the problem here is in front of the keyboard. I am following Kevin Yank’s very nice beginners guide to MySQL and PHP. Here is the specific page I have a problem with. http://dev.mysql.com/tech-resources/articles/ddws/17.html

I have copied and pasted directly into the file and still cant get any value returned. The url query that is in the HTML looks like this,

<A HREF="welcome.php?name=Kevin"> Hi, I'm Kevin! </A>

The PHP like this,

<?php
  echo( "Welcome to our Web site, $name!" );
?>

The non working example is here: http://pixelsnot.com/db_test_site/hi.html.

I hope this easy enough for someone here. I’m sure it is. Thank you very much for your time.

My server is running PHP 5.2.17

There is some code you are not showing (or it is missing).
I no longer own that book - so cannot reference the page precisely - but you need to capture the GET parameter like this (above the code you posted)


<?php $name = $_GET['name']; ?>

Is there a paragraph in the book you missed? Did two pages stick together?

HTH

It’s quite possible that the book, if it’s an older copy, might be using register_globals, which is evil, old and deprecated. Whatever you do, don’t ever turn register_globals on. It will ruin your life and demand the soul of your first-born.

Register_globals makes all GET, POST, COOKIE fields available in your script as regular variables. While this seemed handy at first, it turns out it’s a major security hole, which eventually lead to thousands of sites being defaced/ hacked.

As ParkinT shows, you need to specifically retrieve the variable you need from the superglobals it’s in (GET, POST, COOKIE, ENV etc).

Edit>>
Just noticed you’re using an online version of the guide. You might need to find an updated version of the guide, as this is a very very old version.

Thanks above!

I am familiar with turning register_globals off in a few projects. Since the guide isn’t dated I wasn’t sure if the world of PHP had changed around the tutorial. And that does indeed seem to be the case.

I used the _GET param and it worked great. Thank you. I will tread carefully though the rest of this lesson with an understanding that it is dated.

Thank you both very much for the help.