Jump to content

$_GET Key


Baving

Recommended Posts

I am currently using this script: -

[code]<? if ($_GET) {

$mode = key($_GET);
print $mode;
}

?>[/code]

Which is grabbing the text on the $_GET. But this is only collecting the first bit of information e.g.:-

index.php?permission

It would only print permission.

Is there anyway so that it will get more information from the $_GET statment? e.g.

index.php?permission&group=A

So it would print

permission&group=A

Thanks.
Link to comment
https://forums.phpfreaks.com/topic/22764-_get-key/
Share on other sites

well there are many ways to access parts of a query string like that. try these out and see what you get:
[code]
<?php
// entire query string
echo $_SERVER['QUERY_STRING'];

// individual items:
foreach ($_GET as $key => $val) {
  echo "{$key} => {$val}<br />\n";
}
?>
[/code]

good luck
Link to comment
https://forums.phpfreaks.com/topic/22764-_get-key/#findComment-102469
Share on other sites

[quote author=obsidian link=topic=110257.msg445375#msg445375 date=1159807699]

[code]
<?php

// individual items:
foreach ($_GET as $key => $val) {
  echo "{$key} => {$val}<br />\n";
}
?>
[/code]

good luck
[/quote]

That is what I am needing :)

Any ideas how I could return the array to insert it into a database?

So..

$query = mysql_query("INSERT INTO whatever (list) VALUES('$input')");

With $input being the contents of the foreach array?

Link to comment
https://forums.phpfreaks.com/topic/22764-_get-key/#findComment-102480
Share on other sites

or, just do it all at once in your query if that's what you're after:
[code]
<?php
$q = mysql_query("INSERT INTO table (" . implode(',', array_keys($_GET)) . ") VALUES ('" . implode("','", $_GET) . "')");
?>
[/code]

don't forget to implode() with the quotes around all your values
Link to comment
https://forums.phpfreaks.com/topic/22764-_get-key/#findComment-102486
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.