第二选择不会POST

时间:2013-10-03 21:16:00

标签: php mysql forms post

我的表单包含两个<select>标记:

<li>
    <label for="uname">Select User : </label>
    <select id="uname" name="uname">
        <option value="3">Kaine McAuley</option>
    </select>
</li>
<li>
    <label for="uweek">Week Number : </label>
    <select id="uweek" name="uweek">
        <option value="1">Week 1</option>
        <option value="2">Week 2</option>
        <option value="3">Week 3</option>
        <option value="4">Week 4</option>
        <option value="5">Week 5</option>
        <option value="6">Week 6</option>
        <option value="7">Week 7</option>
        <option value="8">Week 8</option>
        <option value="9">Week 9</option>
        <option value="10">Week 10</option>
        <option value="11">Week 11</option>
        <option value="12">Week 12</option>
    </select>
</li>

这就是它在浏览器中的表现。我echo的内容$_POST并且uweek不存在。但是,uname会这样做!

我创建表单的实际PHP代码如下:

echo '<h2>Update Users</h2><form action="" method="post">
    <ul style="list-style: none;">
            <li>
            <label for="uname">Select User : </label>
            <select id="uname" name="uname">';
while($r = mysqli_fetch_assoc($sql))
{
    switch($r['Username'])
    {
        case 'Mike':
        case '3rungohan':
        case 'Test':
        case 'Jestress':break;
        default: echo '<option value="' . $r['UserID'] . '">' . $r['RealName'] . '</option>';
    }
}

echo '</select></li>
<li>
    <label for="uweek">Week Number : </label>
    <select id="uweek" name="uweek">';
    for($i=1;$i<13;$i++)
    {
        $week = "Week " . $i;
        echo '<option value="' . $i . '">' . $week . '</option>';
    }
    echo '</select>
</li>
<li>
    <label for="uaims">Week Aims : </label><br />
    <textarea id="uaims" name="uaims" rows="4" cols="40" required="required"></textarea>
</li>
<li>
    <label for="upros">Week Progress : </label><br />
    <textarea id="upros" name="upros" rows="4" cols="40" required="required"></textarea>
</li>
<li>
    <label for="unote">Week Notes : </label><br />
    <textarea id="unote" name="unote" rows="4" cols="40" required="required" placeholder="If no notes, just enter: No notes"></textarea>
</li>
<li>
    <input type="submit" value="Submit" />
</li>
</ul>
</form>';

print_r($_POST);

的结果
Array ( [uname] => 3 [uaims] => Aims [upros] => Nope [unote] => No )

来自var_dump($_REQUEST);

的类似结果
array(4) { ["uname"]=> string(1) "3" ["uaims"]=> string(4) "Aims" ["upros"]=> string(4) "Nope" ["unote"]=> string(2) "No" }

$_POST执行完成后,我的代码(在php文档的顶部): 很抱歉无休止的查询我需要来自不同表格的几轮信息。

if(!empty($_POST['uname']))
{
    foreach($_POST as $k => $v) {$up[$k] = $v;}
    $sql2 = mysqli_query($link, "SELECT * FROM jestresstracker WHERE UserID='" . mysqli_real_escape_string($link, $up['uname']) ."' ORDER BY WeekNum DESC LIMIT 1");
    $temp = mysqli_fetch_assoc($sql2);
    $sql3 = mysqli_query($link, "SELECT * FROM jestress_users WHERE UserID='" . mysqli_real_escape_string($link, $up['uname']) ."' LIMIT 1");
    $r = mysqli_fetch_assoc($sql3);
    foreach($r as $k => $v) {$User[$k] = $v;}
    if(!empty($temp['WeekNum']))
    {
        if($up['uweek']<=$temp['WeekNum']) {$result = "Error. Update already set for this week. Week Num: " . $temp['WeekNum'];}
    }
    else {
        $ins = mysqli_query($link, "INSERT INTO jestresstracker (UserID, WeekNum, WeekAims, WeekPro, Updated, UpdatedBy, Notes) VALUES('" . mysqli_real_escape_string($link, $up['uname']) . "', '" . mysqli_real_escape_string($link, $up['uweek']) . "', '" . mysqli_real_escape_string($link, nl2br($up['uaims'])) . "', '" . mysqli_real_escape_string($link, nl2br($up['upros'])) . "', NOW(), '" . mysqli_real_escape_string($link, $res['UserID']) . "', '" . mysqli_real_escape_string($link, nl2br($up['unote'])) . "')");
        if($ins) {$result = "Successfully updated " . $User['RealName'] . "'s Week " . $up['uweek'] . " post.";var_dump($_REQUEST);}
        else {$result = "Error: " . mysqli_error($link);}
    }
}

编辑:更改ID /名称不会返回不同的结果。

3 个答案:

答案 0 :(得分:1)

在这种情况下,最好的朋友是firebug或任何网络分析工具..

检查标题并确保相关字段确实通过..

发布

我认为这可能会有很大帮助..

答案 1 :(得分:0)

您的php或网络服务器似乎有问题。尝试使用此函数自己创建$_POST数组:

function decodePost(){
    $var = file_get_contents('php://input');
    $postContent = explode('&',$var);
    for($i = 0; $i < count($postContent); $i++){
        $postContent[$i] = urldecode($postContent[$i]);
        $map = explode('=', $postContent[$i]);
        $post[$map[0]] = $map[1];
    }
    return $post;   
}

看看是否有任何变化。

答案 2 :(得分:0)

您没有给出包含表单和所有字段的所有HTML代码。

你有很多吗?他们是大/长?

您的php.ini配置有限制吗?检查post_max_size值。

您的服务器上是否安装了suhosin模块? (检查phpinfo()以确定)。 Suhosin有时可能很棘手,它会记录系统日志(例如/var/log/syslog),而不是登录Web服务器日志(例如Apache日志)。

尝试在suhosin.ini中检查这些默认值:

suhosin.post.max_array_depth = 100
suhosin.post.max_array_index_length = 64
suhosin.post.max_name_length = 64
suhosin.post.max_totalname_length = 256
suhosin.post.max_value_length = 1000000
suhosin.post.max_vars = 1000

同时使用W3 validator检查您的HTML代码,以确保所有内容都已正确格式化。也许你的浏览器很奇怪,因为它。

您是否有jQuery onSubmit函数或在Javascript代码中捕获提交的内容?