Simolius
Simolius

Reputation: 77

Trying to pass variable in url

I'm echoing this form:

 echo "<form action='/leaguemaster/fichaTorneio.php?id=" . $_GET['torneioid'] . "'>";

When I submit the form and it links to the page from the action, the variable I'm passing doesn't reach the page...

/leaguemaster/fichaTorneio.php?

I've done this in other pages and it worked, I don't know what's going on here. I've tried having the same form outside a PHP echo and I get the same result.

-EDIT-

This is the full form:

echo "<form method='GET' action='/leaguemaster/fichaTorneio.php?id= " . $_GET['torneioid'] . "'>";
echo "<input type='submit' value='Voltar'>";
echo "</form>";

Upvotes: 2

Views: 57

Answers (3)

SaidbakR
SaidbakR

Reputation: 13534

Use hidden type form's element named id:

 echo "<form action=\"/leaguemaster/fichaTorneio.php\">";
 echo "<input type=\"hidden\" name=\"id\" value=\"$_GET[torneioid]\" />"

Notice: I did not set the method attribute to the form because the GET method is the default method for HTML forms and it makes the form submits its values through the URL query string.

Upvotes: 2

Harsha Kuchampudi
Harsha Kuchampudi

Reputation: 153

There are several things that you should check:

$_GET['torneioid']

This indicates that you are attempting to resolve form or other variables through GET. Make sure that you are passing information through GET and not POST.

Also make sure there is something that is actually stored in torneioid, and that the form or database that you are 'GETting' from, actually holds a value.

Upvotes: 0

Terry Lin
Terry Lin

Reputation: 2599

Please try

 // check $_GET['torneioid'] value
 echo 'torneioid = ' . $_GET['torneioid'] . '<br />';

 echo '<form action="/leaguemaster/fichaTorneio.php?id=' . $_GET['torneioid'] . '">';

And make sure the URL contains "http:// yourdomain.com/?torneioid=something"

Upvotes: 0

Related Questions