Xampp PHP server GET works Fine POST isn't wor

2019-07-10 17:36发布

问题:

I was building a basic php site for my school assignment and I realised that I'm not receiving any data on my save php page. After that I switch my method to GET and my pages works perfectly. Here is my form page

<form action="save-input.php" method="POST">
    <div class="form-group">
        <label for="todoTitle">Todo Title</label>
        <input type="text" class="form-control" name="todoTitle" id="todoTitle" placeholder="Example Title" required>
    </div>
    <div class="form-group">
        <label for="todoShortExplanation">Short Explanation</label>
        <input type="text" class="form-control" name="todoShortExplanation" id="todoShortExplanation" placeholder="Short Explanation for Todo">
    </div>
    <div class="form-group">
        <label for="todoImportance">Importance Level: </label>
            <?php
            // Establish connection and check it's solid or not
            try {
                $conn = new PDO("mysql:host=hostname;dbname=databasename", 'username', 'password');
                $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                //echo "Connected successfully";
            }
            catch(PDOException $e)
            {
                echo "Connection failed: " . $e->getMessage();
            }
            // Create Query and prepare
            $sql = 'SELECT * FROM todoImportance';

            $cmd = $conn->prepare($sql);
            // Execure and fecth the data coming from DB
            $cmd->execute();

            $datas = $cmd->fetchAll();

            // Close connection
            $conn = null;

            //echo '<pre>' . var_export($datas) . '</pre>';
            echo '<select name="todoImportance" id="todoImportance">';

            // Print out dropdown options
            foreach($datas as $data) {
                echo '<option value="' . $data['ImportanceColor'] . '">'. $data['importanceLevel'] . '</option>';
            }

            echo '</select>';
            ?>
    </div>
    <div class="form-group">
        <label for="todo">Todo</label>
        <textarea name="todo" id="todo" class="form-control" rows="4" required></textarea>
    </div>
    <div class="form-group">
        <label for="todoAlarmDate">Alarm Date</label>
        <input type="date" class="form-control" name="todoAlarmDate" id="todoAlarmDate" min="<?php echo date("Y-m-d"); ?>">
    </div>
    <button type="submit" class="btn btn-primary">Save</button>
</form>

After I get the values from user I'm passing those datas to save page. Here is my page I comment everthing out so it's just this

<?php
/**
 * Created by PhpStorm.
 * User: User
 * Date: 2016-02-09
 * Time: 3:50 PM
 */


var_dump($_POST);

Results are "array(0) { }". And I would like to add this If I upload this to the actual web server it works without problem. I did some research before I post this so I looked my php.ini my post_max_size is 128M. I think problem is Xampp server so If you guys could help me I'll be glad.

回答1:

if URLs looks like http://localhost:63342/{PROJECT_NAME}/save-input.php, it tells that you are using PhpStorm's (or other IDE's) built in web server.

If you want to use your proper web server (e.g. Apache) then please create and configure Deployment entry and mark it as Default for this project -- if no deployment specified (that's where IDE takes base URL from) PhpStorm will use built-in web server.

That's the way I solved my trouble.