Insert, update and get in the same php file? I'm creating a CRUD page. My first approach was use the same class editCategory.php for doing these actions:


If this file is called via GET and categoryId parameter doesn't exist -> shall show a empty form
If this file is called via GET and categoryId parameter is provided -> shall show a form with the data of this category.
If this file is called via POST and there is no categoryId parameter -> shall create a new category.
If this file is called via POST and categoryId parameter is provided -> shall update this category.


The code works ok, but I have the sense that the code is cluttered and that it could be organized better. 

    &lt;?php
        require_once "../include_dao.php";
        $action = isset($_POST["action"]);

        $category = new Category();
        $categoryDao = new CategoryMySqlDAO();

        $categoryName = "";
        if ($action == "save") {                                        // DO_POST
            $categoryName = $_POST["name"];
            $category-&gt;name=$categoryName;

            if (isset($_POST["categoryId"])) {                              // update
                $categoryId = (int) $_POST["categoryId"];
                $category-&gt;categoryId=$categoryId;
                $categoryDao-&gt;update($category);
            } else {                                                        // insert
                $categoryDao-&gt;insert($category);
            }
            $messageSuccess = "Category saved";
        } else {                                                        // DO_GET
            if (isset($_GET["categoryId"])) {
                $categoryId = (int) $_GET["categoryId"];

                $category = $categoryDao-&gt;load($categoryId);
                $categoryName = $category-&gt;name;
            } 

        ?&gt;
&lt;html&gt;
 HTML code here showing the form
&lt;/html&gt;
Your concept using the HTTP verbs is pretty much the idea behind REST. You could go one step further and use the less known verbs like PUT, DELETE, UPDATE. 

Also u could use the $_SERVER['REQUEST_METHOD'] to switch between the HTTP modes you would like to process. 

I would suggest to write a "class Request" to be reused by all your CRUD pages or use / get inspired by (for example) symfony2 

https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/Request.php

u are using classes like CategoryMySqlDAO why do not u use a CRUD class? u could implement an abstract class CRUD with "create, update, delete" methodes and then use subclasses for each crud page. Then you would inject the DAO and stuff in the constructor and use autoload to get them instead of a smelly required statement in each file. 

also having HTML and logic in the same file never is a good idea. 

i hope i could give you some inspiration how to improve your current state