Jump to content


navigation


5 replies to this topic

#1 b00g3R

    Young Padawan

  • Members
  • Pip
  • 81 posts
  • Gender:Male
  • Location:Chicago, IL, USA

Posted 25 May 2006 - 02:27 AM

ok i so i saw this tutorial that talked about a nav that uses switch statement $_GET[‘change’]

ex.
switch($_GET['change']){

case 'password':

echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">
<p>Current password:<br>
<input name="current" type="password"></p>
<p>New password:<br>
<input name="new" type="password"></p>
<p>Confirm new password:<br>
<input name="confirm" type="password"></p>
<p><input type="submit" value="Change Password" name="changepassword"></p>
</form>
';

break;

case 'email':

echo '<p>
WARNING! - By changing your email address you will have to re-validate. Make sure you email address is 100% correct.</p>
<form action="'.$_SERVER['PHP_SELF'].'" method="post">
<p>Current email:<br>
<input name="current" type="text"></p>
<p>New email:<br>
<input name="new" type="text"></p>
<p>Confirm new email:<br>
<input name="confirm" type="text"></p>
<p><input type="submit" value="Change Email" name="changeemail"></p>
</form>
';

break;

default:

echo '<p>Welcome to the super secret members only control panel!</p>';

}

?>

the thing is i want to keep that switch($_GET['change']){ but i want to make some new links that deal with switch($_GET['whatever']){ how do i do that? cuz when i do try it by adding some code of the same thing after the last bracket "}" it works but gives me that default echo on the same page..


thx guys

#2 Mr. Matt

    Moderator

  • P2L Staff
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 25 May 2006 - 03:57 AM

firstly by putting it out after that last bracket it means you are putting it outside of the function itself.

you need to add the new one above the default value:
break;

case 'your_case':

echo 'What you want to echo';

hope that helps

#3 b00g3R

    Young Padawan

  • Members
  • Pip
  • 81 posts
  • Gender:Male
  • Location:Chicago, IL, USA

Posted 25 May 2006 - 09:53 AM

here is the code im trying to use

<?php

switch($_GET['id']){

	case 'password':
	
		echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">
		<p>Current password:<br>
		<input name="current" type="password" class="textBox"></p>
		<p>New password:<br>
		<input name="new" type="password" class="textBox"></p>
		<p>Confirm new password:<br>
		<input name="confirm" type="password" class="textBox"></p>
		<p><input type="submit" value="Change Password" name="changepassword"></p>
		</form>
		';
		
		break;
		
	case 'email':
	
		echo '<p>
		WARNING! - By changing your email address you will have to re-validate. Make sure you email address is 100% correct.</p>
		<form action="'.$_SERVER['PHP_SELF'].'" method="post">
		<p>Current email:<br>
		<input name="current" type="text" class="textBox"></p>
		<p>New email:<br>
		<input name="new" type="text" class="textBox"></p>
		<p>Confirm new email:<br>
		<input name="confirm" type="text" class="textBox"></p>
		<p><input type="submit" value="Change Email" name="changeemail"></p>
		</form>
		';
		
		break;
		
	case 'account':
	
		echo '<p>
		WARNING - By closing your account, you will not be able to login again under this account. Press the button below to confirm you wish to close your account</p>
		<form action="'.$_SERVER['PHP_SELF'].'" method="post">
		<p><input type="submit" value="Close Account" name="closeaccount"></p>
		</form>
		';
		
		break;
	
	default;
	
	echo '<p>Welcome to the super secret members only control panel!<br>';
	
		
		break;
		
}
		
switch($_GET['news']){

	case 'news':
	
		include('news/news.php');
		
		break;

}

?>

see thats what i have... see where news is...

well that links works for like this member.php?news=news it comes up but it ends up having that
	default;
	
	echo '<p>Welcome to the super secret members only control panel!<br>';
	
		
		break;

at the top of the page..

Edited by b00g3R, 25 May 2006 - 09:54 AM.


#4 Mr. Matt

    Moderator

  • P2L Staff
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 25 May 2006 - 11:13 AM

well firstly the default needs to have a : not a ; at the end of it, and i am not sure the break is needed after the default, try it with and without. i usualy lay my switch() out like this:

$id = $_GET[id];

switch ($id) {
default: include('home.php');
break; case "home": include('home.php');
break; case "about": include('about.php');
break; case "cartoons": include('cartoons.php');
break; case "jokes": include('jokes.php');
break; case "comments": include('comments.php');
break; case "links": include('links.php');
break; case "register": include('register.php');
break; case "contact": include('contact.php');
}

Edited by deadly, 25 May 2006 - 11:13 AM.


#5 Indigo

    Official Alien

  • Members
  • PipPipPip
  • 617 posts
  • Gender:Male
  • Location:Trondheim, Norway
  • Interests:Computing in general, especially design and programming of all kinds.

Posted 26 May 2006 - 06:35 AM

You could also do something like this:
 
$id = $_GET[id];

switch ($id) {
default: include('home.php');
break; case "about": if(file_exists('about.php')) { include('about.php'); }  else { include('error.php'); }
break; case "tutorials": if(file_exists('tutorials.php')) { include('tutorials.php'); }  else { include('error.php'); }
}

Dunno if this works, but I saw something similliar to this in another topic a while ago. It simply checks if the file really exists, and if it does, include it, if not, include an error. I use the same method in my switches, except that I get my info from databases.

#6 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 26 May 2006 - 12:16 PM

http://php.net/manua...ures.switch.php





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users