Jump to content

Problem with passing variable in URL


markkanning

Recommended Posts

Hey folks,

I may have a variable declaration problem with a script I'm tearing my hair out about. The script is checking whether or not a variable has been passed. If it has, it builds a page based on a series of functions that use that variable for MySQL stuff. If the variable hasn't been passed, it builds another page with a <select> dropdown in a form whose action will re-run the same page with the passed variable.

 

The problem is I keep getting an error from both IE and Firefox that says the page with the "?variable=1" appended to the URL is "Invalid". Even if I hardcode the URL into the address bar like "http://www.domain.com/page.php?stationid=1", it gives me the "Invalid" error. I know the URL is technically just fine, which makes me think the script itself is bunkus.

 

Here's the initial page:

<?php 

include ($_SERVER['DOCUMENT_ROOT'].'/config.php');

//If stationid has been passed, display admin page
if(isset($_GET['stationid'])) {
adminHeader();
chooseDisplayStation();
adminBoxContent();
adminFooter();
}

//Check if stationid has been passed - If not, give them the "choose station" dialogue box
else {
adminHeader();
chooseStation();
adminBoxSecurity();
echo "<center><b>Welcome to the Website Administration Console.</b><br>\n
Please choose a station to edit in the station box above.</center>";
adminFooter();
}
?>

 

Each page being built by the previous script has a "Choose Station" form that looks like this:

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" name="choosestation">
<select onchange="document.location.href=this.options[this.selectedIndex].value;">
<option> -- </option>
<?php
include ($_SERVER['DOCUMENT_ROOT'].'/db/dbconnect.php');
$query = "select * from stations order by stationid";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
for ($i=0; $i < $num_results; $i++) {
	$row = mysql_fetch_array($result);
	echo "<option value=\"?stationid=".stripslashes($row["stationid"])."\">".stripslashes($row["stationname"])."</option>\n";
}
?>
</select>
</form>

 

So far changing anything about the <form> yields no results, making me think it's just fine.

However, in the first page, I've changed the "isset" code with some different results.

 

I've changed this:

if(isset($_GET['stationid']))

to this:

if(isset($_POST['stationid']))

and I don't get the error. However, I also don't get the variable passed, either, and end up with the first "Choose Station" page over and over.

 

Anyone got some input?

Link to comment
https://forums.phpfreaks.com/topic/36813-problem-with-passing-variable-in-url/
Share on other sites

Change

 

<select onchange="document.location.href=this.options[this.selectedIndex].value;">

 

to

 

<select onchange="document.location.href=this.options[this.selectedIndex].value;" name="stationid">

 

You simply left out the drop downs' name so it wouldn't pass the variable because it wasn't given.

I've actually tried that. It doesn't make a difference and it shouldn't being that the <option> value is the "?stationid=". I also tried adding the <select name="stationid"> with <option value=".stripslashes($row["stationid"])."> and that only passing in the URL like "http://www.domain.com/1" which, of course, does nothing.

 

*sigh*

Um...I think I gave you an older version of that <form> code because I've since added the method="get" and, well...no luck there, either. Same result.

 

Does it have something to do with this...

<?php echo $_SERVER['PHP_SELF']; ?>

Is there another method of posting a script to itself that parses the URL differently?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.