Answer the question
In order to leave comments, you need to log in
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
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
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;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question