7

我有一个包含两个<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'd 的内容,$_POSTuweek那里不存在。然而,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/name 不会返回不同的结果。

4

3 回答 3

1

在这种情况下最好的朋友是萤火虫或任何网络分析工具。

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

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

于 2013-12-04T08:07:36.877 回答
0

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

你有很多吗?它们大/长吗?

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

你的服务器上安装了 suhosin 模块吗?(检查phpinfo()确定)。Suhosin 有时可能很棘手,它会登录系统日志(例如/var/log/syslog)而不是登录网络服务器日志(例如 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 验证器检查您的 HTML 代码,以确保所有内容的格式正确。也许您的浏览器因此而表现得很奇怪。

你有 jQueryonSubmit函数或在 Javascript 代码中捕获提交的东西吗?

于 2013-12-05T09:05:44.657 回答
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;   
}

看看有没有什么变化。

于 2013-10-03T21:45:46.823 回答