开发者

Undefined variable - Passing a variable through the url

I get cant get my variable to e开发者_开发百科cho 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?


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 ) );
?>'>


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

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


<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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜