toolman Posted December 20, 2009 Share Posted December 20, 2009 Hi there, I am setting up a simple events system which will allow me to add events to my website. I have a page called events.php, but wanted to set it up so when I add an event, the page is something like: events.php?action=add How do I get the ?action=add part? Do I just insert my form on the events.php page? Any help would be appriciated Thanks Link to comment https://forums.phpfreaks.com/topic/185797-how-do-i-use-something-like-actionadd/ Share on other sites More sharing options...
ChemicalBliss Posted December 20, 2009 Share Posted December 20, 2009 These are called "GET Requests". To use them here is a simple template: <?php // isset() = check if a variable is set (isset). $_GET is an assosciation array (names of the variables with the values). if(!isset($_GET['action'])){ echo("Page 1 <br />"); echo("<a href='?action=page2'>Go to page 2</a>"); }elseif($_GET['action'] == "page2"){ echo("Page 1"); }else{ echo("Page doesnt exist"); } ?> Hope this helps, -CB- Link to comment https://forums.phpfreaks.com/topic/185797-how-do-i-use-something-like-actionadd/#findComment-981060 Share on other sites More sharing options...
keldorn Posted December 20, 2009 Share Posted December 20, 2009 In addition, you should use switch() for the action, like <?php $action = isset($_GET['action']) === true ? $_GET['action'] : ""; switch($action){ // case matches action case 'foo': echo "foo"; break; // exit switch were done case 'bar': echo "bar"; break; // defaults here if action does not exist, you can use this to your advantage to just throw an error default: header("HTTP/1.0 404 Not Found"); $action = htmlentities($action); exit("Action ( {$action} ) undefined."); break; } You can copy that and save it as a PHP file and do this test.php?action=foo test.php?action=bar test.php?action=will_throw_error Link to comment https://forums.phpfreaks.com/topic/185797-how-do-i-use-something-like-actionadd/#findComment-981074 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.