开发者

Handling Multiple POST Requests in one PHP file or Separate

开发者 https://www.devze.com 2023-03-19 21:07 出处:网络
I am new to PHP as you may be able to tell from the question. What I have is an iOS application that accesses a database 开发者_StackOverflow中文版via an apache server using a php front end. I have ma

I am new to PHP as you may be able to tell from the question.

What I have is an iOS application that accesses a database 开发者_StackOverflow中文版via an apache server using a php front end. I have managed to get a user inserted into the database using a POST on a php script called NewUser.php

The thing I am struggling with is how to organize the files and whether or not I need multiple php scripts for each query I want to run on the database or I am able to handle each different POST request in the same script?

As I said I am new to the concept of PHP. If anyone could point me in the right direction to maybe a tutorial or give me some pointers on here that would be great!

Disco


yes, you can handle more type of POST requests in one script.

For example script name is action.php and inside is code:

switch ($_POST['action']) {
   case 'insert_user':
       // code for inserting new user
       break;
   case 'delete_user':
       // code for deleteing user
       break;
   // and so on ...
}

and when are you doing POST request you will have to add parameter action which one will indetify the correct action.

POST /action.php HTTP/1.1
Some headers

action=insert_user&name=John&surname=Doe....
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号