我有一个包含两个<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 的内容,$_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/name 不会返回不同的结果。