...

View Full Version : Resolved function/url help



Manix
05-24-2011, 10:11 AM
Hey guys, I am hoping someone can help me here. I have done search after search for the last several hours and cant find my solution. I am currently starting a website, and here is what I am trying to achieve. Instead of having a bunch of pages trying to use the same page with functions inside it.




function main(){
/* my code here */
/* emphasis on the ?action=action */
echo "<a href=index.php?action=signup>Signup</a>";
}

function signup(){
/* show signup page */
}



Can someone please get me pointed in the right direction?



switch($action){

case "main";
main();
break;

case "signup";
signup();
break;
}

tangoforce
05-24-2011, 01:25 PM
I think this is probably what you're trying to achieve:



<?
switch($_GET['action'])
{
case "signup";
signup();
break;

default;
main();
break;
}

function main()
{
print <<<STOP
<html>
echo "<a href=index.php?action=signup>Signup</a>";
</html>
STOP;
}

function signup()
{
print <<<STOP
<html>
<!--/* show signup page */-->
</html>
STOP;
}
?>

Manix
05-25-2011, 04:32 AM
ok here is my current code




if(!isset($_GET['action'])) {
$action = "userMain";
}

function userMain(){

echo "<a href=account.php?action=signup>Sign-Up";
echo "<input type=\"hidden\" name=\"action\" value=\"signup\">";
$stop;
}

function Signup(){
if ($_SERVER['REQUEST_METHOD'] == "POST"){
encryptPassword();
insertUser();
} else {

/* form code here */


}
$stop;
}


switch($_GET['action']) { /* <-- Line 105 */

case "Signup":
Signup();
break;

default;
userMain();
break;

case "userMain":
userMain();
break;
}



Notice: Undefined index: action in C:\wamp\www\account.php on line 105

the link shows up, and when clicked i still see the link but the error dissapeares.

bullant
05-25-2011, 04:48 AM
That error message is telling you there is no parameter named "action" in the query string attached to the url of your php script.

Looks like you just need to do some Basic Debugging 101 (http://www.codingforums.com/showthread.php?p=1082858#post1082858).

Manix
05-25-2011, 08:17 AM
is there somewhere i can read that tells what that is and how it works when the url is like that

whatever.php?blah=this

Manix
05-25-2011, 11:30 AM
i figured out my problem




$action = (isset($_GET['action'])) ? $_GET['action'] : "index";

switch($action) {


default:
index();
break;

case "signup":
signup();
break;

case "forgotPassword":
forgotPassword();
break;

}

function index(){

echo "This is index<br />";
echo "<a href=./test.php?action=signup>Sign-Up<br />";
echo "<a href=./test.php?action=forgotPassword>Forgot Password";

}

function signup(){
echo "this is signup";
}

function forgotPassword(){

echo "this is the forgot password area";
}

tangoforce
05-25-2011, 01:13 PM
I think your problem was the use of the variable $stop.

That isn't the same as I showed you. I showed you the use of a heredoc:

<<< <label>

<label>



print <<<STOP //Print until stop
<html>
</html>
STOP; //STOP must be at the very left. No spaces, no tabs, No $ in front.
//Just the word exactly as you see if after <<< followed by a semicolon.

tangoforce
05-25-2011, 01:18 PM
Further, the default: action in your switch should be at the bottom as the LAST option.

I've shown you how to use this correctly in my example.

The default is supposed to be at the bottom so that it can handle anything the clauses above did not handle. By putting it at the top you're screwing with the way the switch was designed to work. Just like your twist on using $stop, you can't just take switch and decide to rewrite its mechanism for your own needs.

I gave you good code to use. All you had to do was copy it and modify it to your needs.

Inigoesdr
05-25-2011, 05:46 PM
Further, the default: action in your switch should be at the bottom as the LAST option.

I've shown you how to use this correctly in my example.

The default is supposed to be at the bottom so that it can handle anything the clauses above did not handle. By putting it at the top you're screwing with the way the switch was designed to work.

The default switch option doesn't need to be at the bottom, though you can argue that it's good for logical readability.

tangoforce
05-25-2011, 07:22 PM
Well yes because otherwise it takes responsibility for everything. If its at the top then there is no point having other cases after it.

Lines of code do run from top to bottom..

Inigoesdr
05-25-2011, 09:22 PM
You didn't understand me. The default case placement does not matter. It performs the exact same way whether it's at the top, bottom, middle, etc.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum