使用POST传递值不起作用 - PHP

时间:2017-08-05 23:06:51

标签: php mysql

我有以下代码..我试图弄清楚为什么wEx1值没有被传递给PHP代码而wDate是。我有名称='wEx1'属性,我已经尝试了直接$ _POST []来获取它以及转义字符串,即使它不是来自用户的输入字段。无论哪种方式,我都无法让它出现在php端的echo语句中。任何想法和帮助表示赞赏!

<form class='navbar-form' method='post' action='enterWorkoutPlan.php' onsubmit='return validateWorkoutPlan()' name='workoutPlanForm'>
    <div class='form-group'>

    ...other stuff here..

        <b>Exercise 1: </b>

        <select class='form-control' name='wEx1'>
            <!-- Have default be Select Exercise for how many exercises are chosen check -->
            <option value='Select exercise' selected>Select exercise</option>
            <?php
                $sql2 = "SELECT exName FROM exercises";
                $result2 = mysqli_query($db, $sql2);
                if ($result2){
                    while($row2 = mysqli_fetch_assoc($result2)) {
                        echo "
                          <option value='".$row2['exID']."'>".$row2['exName']."</option>";
                    }
                } else {
                    echo "<script>confirm('Error pulling exercises list');</script>";
                }
            ?>                                                  
        </select><br>
    ...other stuff here..

    </div>

    <br><br>
    <input type='submit' value='Save Workout' class='btn btn-primary'>
</form> 

我接受值的PHP页面如下所示..

<?php
include("config.php");
include("userInfo.php");
session_start();

ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);

$wUserID = mysqli_real_escape_string($db,$_POST["wUserID"]);
$wDate = mysqli_real_escape_string($db,$_POST["wDate"]);
$wEx1 = $_POST["wEx1"];
$wEx2 = mysqli_real_escape_string($db,$_POST["wEx2"]);
$wEx3 = mysqli_real_escape_string($db,$_POST["wEx3"]);
$wEx4 = mysqli_real_escape_string($db,$_POST["wEx4"]);
$wEx5 = mysqli_real_escape_string($db,$_POST["wEx5"]);
$wEx6 = mysqli_real_escape_string($db,$_POST["wEx6"]);
$wEx7 = mysqli_real_escape_string($db,$_POST["wEx7"]);
$wEx8 = mysqli_real_escape_string($db,$_POST["wEx8"]);
$wEx9 = mysqli_real_escape_string($db,$_POST["wEx9"]);
$wEx10 = mysqli_real_escape_string($db,$_POST["wEx10"]);
.... etc..

1 个答案:

答案 0 :(得分:-1)

此外,在查询练习列表的地方,您只获取名称而不是ID,因此每个条目的“值”可能是一个空字符串,var_dump()应该显示该字符串。检查选择选项的另一种方法是在页面加载后查看浏览器页面源。 - Paul T. 23分钟前