$ _POST没有提交表单,数组打印为array()

时间:2016-04-23 00:19:30

标签: php arrays forms .htaccess post

下面是我用来向我的本地XAMPP服务器上的数据库提交一个新轮子的表格,问题是post方法不起作用,我遇到了一个模式的问题,该模式是使用排序的$ _GET代替。我已经更改了一些php.ini设置,但更改了它们,max_upload和另一个设置,我已经在其他问题中阅读了它们,但它们似乎无法解决问题。

当我使用下面的提交表单时,打印的数组只是Array(),甚至没有单个值,这应该提示我的错误检查至少打印错误。

<!-- wheels form -->
<div class="text-center">
    <form class="form-inline" action="wheels.php" method="post">
        <div class="form-group">
            <label for="wheelName">Add a new wheel:</label>
            <input name="wheelName" type="text" id="wheelName" class="form-control" value="<?=((isset($_POST['wheelName']))?$_POST['wheelName']:''); ?> "><!-- shorthand if/else-->
            <label for="code">Stockcode</label>
            <input name="code" type="text" id="code" class="form-control" value="<?=((isset($_POST['code']))?$_POST['code']:''); ?> "><!-- shorthand if/else-->
            <input type="submit" name="add_submit" value="add wheel" class="btn btn-success">
        </div>
    </form>
</div><hr>

标准的php sql输入和检查,信息被正确拉出,因为我将它显示在我的页面上的一个表中。但是$ _POST变量似乎是完全空的,有人有这个问题并设法对它进行排序?我假设它与我的php设置或.htaccess有关,因为其他人遇到了问题。

<?php
require_once '../core/init.php';
include 'includes/header.php';
include 'includes/navigation.php';

// Get wheels from DB
$sql = "SELECT * FROM wheels ORDER BY part_no";
$result = $db->query($sql);
$errors = array();

// edit wheel
if(isset($_GET['edit']) && !empty(['edit'])) {
    $edit_id = (int)$_GET['edit'];
    $edit_id = sanitize('edit_id');
    //$sql2 = "SELECT * FROM wheels WHERE recid = '$edit_id'";
    //$edit_result = $db->query($sql2);
    //$eWheel = mysqli_fetch_assoc($edit_result);
}

// Delete wheel
if(isset($_GET['delete']) && !empty(['delete'])) {
    $delete_id = (int)$_GET['delete'];
    $delete_id = sanitize($delete_id);
    //$sql = "DELETE FROM wheels WHERE recid = '$delete_id'";
    //$db->query($sql);
    //header('Location: wheels.php');
}

// If add wheel form submitted
if(isset($_POST['add_submit'])) {
    $wheel = sanitize($_POST['wheelName']);
    $stockCode = sanitize($_POST['stockCode']);

    // check if wheel is blank
    if($_POST['wheelName'] == '') {
        $errors[] .= 'Must enter wheel';
    }

    // if wheel exists in db
    $sql = "SELECT * FROM wheels WHERE stockcode = '$stockCode'";
    $result = $db->query($sql);
    $count = mysqli_num_rows($result);
    if($count > 0) {
        $errors[] .= 'that wheel already exists.';
    }

    // display errors
    if(!empty($errors)) {
        echo displayErrors($errors);
    } else {
        //Add wheels to DB // incomplete unsure if feature needed at this stage.
        // $sql = "INSERT INTO wheels (wheelName, stockCode, ID ETC ETC VALUES Etc ETC
        // $db->query($sql);
        // header ('location : wheels.php ');

    }
}

var_dump($_POST);
echo file_get_contents("php://input");
?>

这是日志

::1 - - [23/Apr/2016:14:12:32 +1200] "GET / HTTP/1.1" 302 - "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36"

::1 - - [23/Apr/2016:14:12:32 +1200] "GET /dashboard/ HTTP/1.1" 200 6904 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36"

::1 - - [23/Apr/2016:14:12:32 +1200] "GET /dashboard/stylesheets/normalize.css HTTP/1.1" 200 6876 "http://localhost/dashboard/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36"

::1 - - [23/Apr/2016:14:12:32 +1200] "GET /dashboard/stylesheets/all.css HTTP/1.1" 200 481308 "http://localhost/dashboard/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36"

::1 - - [23/Apr/2016:14:12:32 +1200] "GET /dashboard/javascripts/modernizr.js HTTP/1.1" 200 51365 "http://localhost/dashboard/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36"

::1 - - [23/Apr/2016:14:12:33 +1200] "GET /dashboard/javascripts/all.js HTTP/1.1" 200 189003 "http://localhost/dashboard/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36"

::1 - - [23/Apr/2016:14:12:33 +1200] "GET /dashboard/images/xampp-logo.svg HTTP/1.1" 200 5427 "http://localhost/dashboard/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36"

::1 - - [23/Apr/2016:14:12:33 +1200] "GET /dashboard/images/bitnami-xampp.png HTTP/1.1" 200 22133 "http://localhost/dashboard/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36"

::1 - - [23/Apr/2016:14:12:33 +1200] "GET /dashboard/images/fastly-logo.png HTTP/1.1" 200 1770 "http://localhost/dashboard/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36"

::1 - - [23/Apr/2016:14:12:33 +1200] "GET /dashboard/images/social-icons.png HTTP/1.1" 200 3361 "http://localhost/dashboard/stylesheets/all.css" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36"

My controller's method to take parameters from second page view (CODE)

1 个答案:

答案 0 :(得分:0)

好吧,我认为您应该将<?php行放在文件的最顶部......在“从数据库获取轮子”评论之前

而不是print_r($_POST);使用var_dump($_POST);

另外,在“如果存在于db中的轮子”一节中你的sql查询从不使用$stockCode变量,你错过了$,它应该是$sql = "SELECT * FROM wheels WHERE stockcode = '$stockCode'";

然后在错误的等号前面放下点。对于字符串,以及作为数组$errors[] = 'that wheel already exists.';应该正常工作