Aside from the issue of alternating between $_GET
and $_POST
, if you want to keep your key value pairs from your GET request, this isn't a big issue. You have multiple options:
Recommended
Check out parse_url()
. This is available from PHP 4 onward. The documentation has plenty of examples:
$url = 'http://username:password@hostname/path?arg=value#anchor';
print_r(parse_url($url));
echo parse_url($url, PHP_URL_PATH);
Alternative
Try a var_dump()
on your $_SERVER
variables. You should be able to see a QUERY_STRING
attribute which you can access with $_SERVER['QUERY_STRING']
. Here, you can manually split your key / values using. Guess what, there's a function for that too!
Check out: parse_str()
. You give it a query string, like that from a GET, and it'll sort out all your key values for you. Check out the documentation, it gives you the following example:
$str = "first=value&arr[]=foo+bar&arr[]=baz";
parse_str($str);
echo $first; // value
echo $arr[0]; // foo bar
echo $arr[1]; // baz
Pretty simple really! Try both these functions - they're there to solve your exact problem. To get the above working for you, I would first try:
var_dump(parse_str($_SERVER['QUERY_STRING']));
In closing, I'll be the one to talk about MySQL deprecation. Here's what I copy / paste to the newbies:
Please, don't use mysql_*
functions in new code. They are no longer maintained, are officially deprecated, and can be dangerous in live code. See the red box? Learn about prepared statements instead, and use PDO, or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.