/    Sign up×
Community /Pin to ProfileBookmark

Help with $_GET[‘foo’]

hi there, i’m processing a form which simply passes a few hidden variables through a page.

[code=php]<form action=’2delete.php’>
<input type=hidden name=jobtitle value=$_GET[‘foo’]>
<input type=submit value=’Go’>
</form>
[/code]

The browser doesn’t like the apostrophes in the [i]$_GET[‘foo’][/i] so when i just put [i]$_GET[foo][/i], if $foo has space in it, for example “nice variable” it truncates it to “nice”, which screws up all my SQL Queries..

[code]Parse error: parse error, expecting `T_STRING’ or `T_VARIABLE’ or `T_NUM_STRING’ in /dir/blah/bar/page.php on line 149[/code]

[/code] (above is the error it returns)

what can i put so that it doesn’t hate spaces, and so it doesn’t return an error?

thanks!

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@sgalmeidaJan 12.2004 — Hi

you miss the <? ?> tags ?)

please look at this


<form action='2delete.php'>

<input type=hidden name=jobtitle value='[COLOR=red]<? echo $_GET['foo']; ?>[/COLOR]' >

<input type=submit value='Go'>

</form>
[/QUOTE]
Copy linkTweet thisAlerts:
@hammerslaneauthorJan 12.2004 — fantastic! thanks very much for the answer... i'm not sure why i didn't think of this myself.

many thanks

regards
Copy linkTweet thisAlerts:
@pyroJan 12.2004 — You might want to think twice about using short tags (<? ?>) if this has any possibility of being used on a different server, as short tags can be disabled. I personally [i]always[/i] use the long tags (<?PHP ?>) for this very reason. Also, if you are going to use short tags anyway, you might as well use the shorthand version:

<?= $_GET['foo']; ?>
Copy linkTweet thisAlerts:
@sgalmeidaJan 12.2004 — please clarify me: whats wrong by using the echo?
Copy linkTweet thisAlerts:
@pyroJan 12.2004 — Nothing at all. The problem is the short tags (<? rather than <?PHP). Short tags can be disabled in the php.ini file, and I highly discourage using them in most instances. The last part of my post above was to simply show that if you are using short tags, you might as well use the shorthand way of echoing a variable.

<?= $var; ?>

is the same as:

<? echo $var; ?>
Copy linkTweet thisAlerts:
@sgalmeidaJan 12.2004 — ohh ? I'm allways learning ?
×

Success!

Help @hammerslane 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.20,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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