D
D
dflbrhekbn2017-10-05 16:52:03
JavaScript
dflbrhekbn, 2017-10-05 16:52:03

Is it possible to access different requests in one php file?

I don’t know how to write the question correctly, but the essence is this:
I have three php files:
forma.php - displays the form by accessing the sql database
delete.php - gets the line id of the line selected in forma.php through the checkbox to delete
insert.php - adds lines to the database entered in type="text
Is it possible somehow to combine all this into one file and access a specific request? for example, as one .js file and there are 10 functions in it, each of which responds to a specific event

Answer the question

In order to leave comments, you need to log in

4 answer(s)
R
Roman Alexandrovich, 2019-06-28
@olya_097

https://jsfiddle.net/xy7zors6/

A
Alexander, 2017-10-05
@Captain

Yes, it is possible and it needs to be regulated by the GET parameter in the URL. And already in the file itself, see that there is a parameter = delete, then delete. If insert, then add. Otherwise, show the form.
http://mysite.ru/index.php?task=delete&id=4

A
Anton, 2017-10-05
@karminski

Of course, this is called routing
www.yiiframework.com/doc-2.0/guide-runtime-routing.html
Usually present in frameworks.
For you, as the simplest option that does not pretend to laurels, I can suggest checking for the presence of the action parameter in the URL. Depending on the value of which, execute one or another piece of code:

switch ($_GET["action"]) {
    case 'forma':
        // your code here
        break;
    case 'delete':
        // your code here
        break;
    case 'insert':
        // your code here
        break;
    default:
        // your code here
        break;
}

P
Philipp, 2017-10-05
@zoonman

Step one phpfaq.ru/newbie/na_tanke
Step two php.net/manual/ru/function.include.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question