/    Sign up×
Community /Pin to ProfileBookmark

$_GET variable question

I want to do something like this

how would I write something like this ?? $_GET[$item] ???

so far

$_GET[$item] does not work… or $_GET[‘$item’] .. What is the proper way to write this?

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJun 18.2007 — $_GET[$item] is syntactically correct. (You could put double quotes around $item and it would still work, but they are superfluous and would probably add a few nano-seconds to the processing time.) If the entire variable is within a double-quoted string, you'll need to use "complex notation":

[code=php]
echo "Hello {$_GET[$item]} world";
[/code]
Copy linkTweet thisAlerts:
@firmanauthorJun 18.2007 — This is what I am trying to do:

from my form... I am pulling $item names... it is a get FORM
[code=html]

<input type="checkbox" name="$item" value="ON"></center>

[/code]


[code=php]

$handle = opendir("../../images/photo_gallery/".$_GET['folder']);





while ($item = readdir($handle)) {

if (($item) AND $item !== '.' AND $item !== '..' AND (stristr($item, 'jpg')!== FALSE) OR (stristr($item, 'gif')!== FALSE)) {




f {$_GET[$item] == "ON"} {

print $_GET[$item];


}


[/code]


This is not working...any idea why??
Copy linkTweet thisAlerts:
@callumdJun 19.2007 — The 3rd last line of your PHP code starts with 'f', that should be an 'if';
Copy linkTweet thisAlerts:
@SheldonJun 19.2007 — also your form name is name="$item" and in your PHP your only looking for $_GET['folder']. Is your form get or post(method)? should those not be the same? and you are using no error checking to check is the data is correct. you have some big security issues.


This is what I am trying to do:

from my form... I am pulling $item names... it is a get FORM
[code=html]

<input type="checkbox" name="$item" value="ON"></center>

[/code]


[code=php]

$handle = opendir("../../images/photo_gallery/".$_GET['folder']);





while ($item = readdir($handle)) {

if (($item) AND $item !== '.' AND $item !== '..' AND (stristr($item, 'jpg')!== FALSE) OR (stristr($item, 'gif')!== FALSE)) {




f {$_GET[$item] == "ON"} {

print $_GET[$item];


}


[/code]


This is not working...any idea why??[/QUOTE]
Copy linkTweet thisAlerts:
@firmanauthorJun 19.2007 — sorry I copied it wrong... I have the f as an IF.... Also.. it is a GET form


the $_GET['folder'] part works correctly... it is pulling JPG and GIF items out of a certain folder..that it does do.... It is just the $_GET[$variable] or as I have it $_GET[$item] I am having trouble with.
Copy linkTweet thisAlerts:
@SheldonJun 19.2007 — well i image its the $ sign that is causing the issue. just name and look for item not $item.

<checkbox name="item" />

$_GET['item'];
Copy linkTweet thisAlerts:
@firmanauthorJun 19.2007 — no.. i am using $item to give it a name... it is using the name of a picture in a folder as the name of the check box...so if the check box is checked...I know it corresponds to a certain photo... the $item is right....
Copy linkTweet thisAlerts:
@SheldonJun 19.2007 — Well, try echo out $item and see, it will return blank because that is not how you set it.
×

Success!

Help @firman spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...