0

I get cant get my variable to echo on the page even though it shows in the URL. Here is the link that passes it

<a href='eventform.php?$eventname'>

And the code to get it on a other page:

$eventname = 0;
if (isset($_GET['eventname'])) {
$eventname = $_GET['eventname'];
}
echo $_GET['eventname'];

It displays the 0 but not the Mountain 2012 which is in the url at the top. Please help me with this problem

Am i displaying it correctly on the other page?

3 Answers 3

3

You need:

  • To give it a name in the query string
  • To sanitise the data for the URI
  • To sanitise the URI for the HTML

Thus:

<a href='eventform.php?eventname=<?php
    echo htmlspecialchars( urlencode( $eventname ) );
?>'>
Sign up to request clarification or add additional context in comments.

2 Comments

It gets rid of the error but it still does not echo the var on the page with my isset code
also the url comes out like this: sportevent/eventform.php?eventname=%3C?php%20%20%20%20echo%20htmlspecialchars(%20urlencode(%20Marathon%202012%20)%20);?%3E
2

You forgot to put eventname= in your url such as:

<a href="eventform.php?eventname=<?php echo $eventname; ?>">

Comments

-1
<a href='eventform.php?<?php=$eventname?>'>

Or:

<a href='eventform.php?<?php echo $eventname?>'>

Although you might want:

<a href='eventform.php?eventname=<?php echo $eventname?>'>

^^sets $_GET['eventname'] to $eventname

2 Comments

be carefull with echo like that. It might be disabled in the php.ini.
@Topener Since PHP 5.4.0, <?= is always available. php.net/manual/en/ini.core.php#ini.short-open-tag

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.