Jump to content

==> .php?doThis


n00b_user

Recommended Posts

Umm.. I think I accidently added this to the subsection >.<  :-\ oopsies, soz

 

So, pardon my noobish question

 

Once upon a time I was able to do this, and I've forgotten everything

(you know, if you don't use it, ya lose it...)

 

Unfourtunatly, I don't even know how to describe it, and I've tried googling it, but I don't know what: ".extension?action=result" is called, specifically because I don't know if "action" is a function, a variable, or a special syntax

 

Here's my quick explanation:

  • I want to be able to put every "action" onto a page called actions.php
  • I then want to click on the Submit button found on index.php
  • The form on index.php is set to: action="actions.php?doThis"
    (Where "doThis" is: addUser, updateUser, etc)

 

Example:

Basically, I want 1 page (actions.php) to do 4 different things. They are:

[*] validate user

[*] add user

[*] update user

[*] delete user

 

I know how to DO all of these things on 4 separate pages, but I don't want 4 separate pages. I want 1 page.

 

Now, I've created my actions.php page

And have tried making "doThis" a function and a variable, and I'm not getting any output

 

I'm sure you've seen this many times before in a link.

Especially when inputting a username and password:

http://www.mysite.com/login.php?userID=785765

 

So my questions are:

[*] What is this called so I know what I'm doing?

[*] How do I do this? As in: what format should "doSomething" be in, so that it registers and outputs what I want it to without having to make 50 different pages?

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/135836-phpdothis/
Share on other sites

action="actions.php?doThis" should be action="actions.php?action=doThis"

 

Then on your actions.php page:

 

<?php
$action = isset($_GET['action'])?$_GET['action']:'none';

if ($action == "none") {
    die("No action provided");
}

switch ($action) {
      case 'add':
             addUser($_POST['username']);
      break;
      case 'delete':
            deleteUser($_POST['delete']);
      break;
}
?>

 

Should get you the desired result.

Link to comment
https://forums.phpfreaks.com/topic/135836-phpdothis/#findComment-708087
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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