6 Replies - 728 Views - Last Post: 13 July 2009 - 04:12 PM Rate Topic: -----

#1 Delta62  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 55
  • Joined: 19-February 09

Odd $_GET problem

Posted 13 July 2009 - 02:06 AM

Hey everyone,

I've been working on a PHP script recently, and I can't seem to get it to work. The program is quite large, so I included the whole thing later if you want to see the entire page.
if (!isset($GET_['step'])) {
	echo "Step is: " . $_GET['step'];
	require('startform.php');
} else {
	switch ($_GET['step']) {
		//...really long code...



I can run the program in a browser and actually get it to tell me "I think step is: 1." However, The if block is called every time the page is loaded, even if it knows that 'step' is set to something (like 1, as I mentioned earlier).

Thanks in advance... this has got me stumped. :blink:

Here's the whole thing:
<?php
function debugDisplay () {
?>
<pre>
	$_POST
	<?php
	print_r($_POST);
	?>
	$_GET
	<?php
	print_r($_GET);
	?>
</pre>
<?php
}

debugDisplay();

if (isset($GET_['step']) == false) {
	echo "I don't think that 'step' is set.";
	echo "<br>I think step is: " . $_GET['step'];
	require('startform.php');
} else {
	switch ($_GET['step']) {

		//#####################
		//SEARCH / ADD FORM
		//#####################
		case "1":
			$type = explode(":", $_POST['type']);
			if ($_POST['Submit'] == "Add") {
				require($_POST['Submit'] . $type[0] . '.php');
			} else {
				if ($_POST['type'] == "Movie:Movie" && $_POST['MovieType'] == "") {
					header("Location:form4.php");
				}
				?>
				<h1>Search Results</h1>
				<p>You are looking for a <?php echo $type[1]; ?>" named "
				<?php echo $_POST['Name']; ?>"</p>
				<?php
			}
			if ($_POST['Dubug'] == "on") {
				debugDisplay();
			}
			break;

		//######################
		//ADD SUMARY
		//######################
		case "2":
			$type = explode(":", $_POST['type']);
			?>
			<h1>New <?php echo $type[1]; ?> : <?php echo $_POST['Name']; ?></h1>
			<?php
			switch ($type[0]) {
				case "Movie":
					?>
					<p>Released in <?php echo $_POST['MovieYear']; ?></p>
					<p><?php echo nl2br(stripslashes($_POST['Desc']));?></p>
					<?php
					break;
				default:
					?>
					<h2>Quick Bio</h2>
					<p><?php echo nl2br(stripslashes($_POST['Bio'])); ?></p>
					<?php
					break;
			}
			break;
		//#########################
		//STARTING FORM
		//#########################
		default:
			require('startform.php');
			break;
	}
}
?>


Is This A Good Question/Topic? 0
  • +

Replies To: Odd $_GET problem

#2 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1003
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: Odd $_GET problem

Posted 13 July 2009 - 02:19 AM

That script looks nice, so I'm not going to tell you the answer... But what's wrong with this:
$GET_['step']


:)
Was This Post Helpful? 0
  • +
  • -

#3 grimpirate  Icon User is offline

  • Pirate King
  • member icon

Reputation: 149
  • View blog
  • Posts: 714
  • Joined: 03-August 06

Re: Odd $_GET problem

Posted 13 July 2009 - 10:56 AM

lol don't be a jerk MageUK he's probably looked it over and just missed it, that happens to me all the time. Delta 62 the line
if (isset($GET_['step']) == false) {
needs to be
if (isset($_GET['step']) == false) {
Typographical errors are the worst, I feel your pain.

This post has been edited by grimpirate: 13 July 2009 - 11:03 AM

Was This Post Helpful? 1
  • +
  • -

#4 Delta62  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 55
  • Joined: 19-February 09

Re: Odd $_GET problem

Posted 13 July 2009 - 11:11 AM

HA!

I can't believe that I missed that!

Thanks, guys. :ph34r:
Was This Post Helpful? 0
  • +
  • -

#5 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1003
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: Odd $_GET problem

Posted 13 July 2009 - 11:20 AM

I wasn't being a jerk, that was a compliment..
Was This Post Helpful? 0
  • +
  • -

#6 Wimpy  Icon User is offline

  • R.I.P. ( Really Intelligent Person, right? )
  • member icon

Reputation: 159
  • View blog
  • Posts: 1,038
  • Joined: 02-May 09

Re: Odd $_GET problem

Posted 13 July 2009 - 12:17 PM

Well, happy you solved the problem but I have to point out that you have a little bad logic in there:
if (!isset($_GET['step'])) {
	echo "Step is: " . $_GET['step'];}

this would result in a PHP Warning, if a variable is not set you can't actually use it either. You do this a couple of times throughout your code and you really should alter it so that it makes sense! :)

This post has been edited by Wimpy: 13 July 2009 - 12:18 PM

Was This Post Helpful? 0
  • +
  • -

#7 Delta62  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 55
  • Joined: 19-February 09

Re: Odd $_GET problem

Posted 13 July 2009 - 04:12 PM

View PostWimpy, on 13 Jul, 2009 - 11:17 AM, said:

Well, happy you solved the problem but I have to point out that you have a little bad logic in there:
if (!isset($_GET['step'])) {
	echo "Step is: " . $_GET['step'];}

this would result in a PHP Warning, if a variable is not set you can't actually use it either. You do this a couple of times throughout your code and you really should alter it so that it makes sense! :)


Yes, I wasn't using the step variable for production purposes, just for error testing. I was finding it funny that the program would print the value of step, even though it had (supposedly) reported that step was not set.

The program is all fixed now, though.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1