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
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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.