此表单根本没有发布值,我无法弄清楚。我已经尝试使用PHP_SELF和单独的页面操作,但没有任何作用。所有其他形式都有效 - 因此它不是服务器问题。我究竟做错了什么?谢谢。
<form name=\"projects\" action=\"upload.php\" method=\"POST\">
<?php
echo "<tr>
<td valign = \"top\" bgcolor=\"$row_color\"> $title </td>
<td valign = \"top\" bgcolor=\"$row_color\"> $description </td>
<td valign = \"top\" bgcolor=\"$row_color\"> $academicdiscipline </td>
<td valign = \"top\" bgcolor=\"$row_color\"> ";
$allowed = $academicdiscipline;
switch ($allowed) {
case "Civil and Environmental":
echo "<select name=\"priority\" class=\"priority\">
<option> </option>
<option value=\"1\"> 1 </option>
<option value=\"2\"> 2 </option>
<option value=\"3\"> 3 </option>
<option value=\"4\"> 4 </option>
<option value=\"5\"> 5 </option>
<option value=\"6\"> 6 </option>
<option value=\"7\"> 7 </option>
<option value=\"8\"> 8 </option>
<option value=\"9\"> 9 </option>
<option value=\"10\"> 10 </option>
</select> ";
break;
case "Electronics":
echo "<select name=\"priority\" class=\"priority\">
<option> </option>
<option value=\"1\"> 1 </option>
<option value=\"2\"> 2 </option>
<option value=\"3\"> 3 </option>
<option value=\"4\"> 4 </option>
<option value=\"5\"> 5 </option>
</select>";
break;
case "Environment and Management":
echo "<select name=\"priority\" class=\"priority\">
<option> </option>
<option value=\"1\"> 1 </option>
<option value=\"2\"> 2 </option>
<option value=\"3\"> 3 </option>
<option value=\"4\"> 4 </option>
<option value=\"5\"> 5 </option>
</select>";
break;
case "Mechanical and Materials":
echo "<select name=\"priority\" class=\"priority\">
<option> </option>
<option value=\"1\"> 1 </option>
<option value=\"2\"> 2 </option>
<option value=\"3\"> 3 </option>
<option value=\"4\"> 4 </option>
<option value=\"5\"> 5 </option>
<option value=\"6\"> 6 </option>
<option value=\"7\"> 7 </option>
<option value=\"8\"> 8 </option>
<option value=\"9\"> 9 </option>
<option value=\"10\"> 10 </option>
<option value=\"11\"> 11 </option>
<option value=\"12\"> 12 </option>
<option value=\"13\"> 13 </option>
<option value=\"14\"> 14 </option>
<option value=\"15\"> 15 </option>
</select> ";
break;
default:
echo "<select name=\"priority\" class=\"priority\">
<option> </option>
<option value=\"1\"> 1 </option>
<option value=\"2\"> 2 </option>
<option value=\"3\"> 3 </option>
<option value=\"4\"> 4 </option>
<option value=\"5\"> 5 </option>
</select> ";
break;
default:
echo "<select name=\"priority\" class=\"priority\">
<option> </option>
<option> 1 </option>
<option> 2 </option>
<option> 3 </option>
<option> 4 </option>
<option> 5 </option>
</select>"; }
echo "</td></tr>
<tr bgcolor=\"#ffffff\"> </tr>
<tr bgcolor=\"#902C2E\"> </tr>";
$row_count++; }
echo"<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td ><input name=\"reset\" type=\"reset\" value=\"Reset\"/>
<input name=\"submit\" type=\"submit\" value=\"Select\"/>
</tr></table>" ; ?>
</form>
upload.php页面可以上传除了优先级之外的所有其他条目,我无法通过上面的代码进行POST。这是upload.php文件:
if(isset($_POST[submit]) && !empty($_POST[submit])) {
$fullname = ''.$data[0]["sn"][0].', '.$data[0]["givenname"][0].'';
$givenname = ''.$data[0]["givenname"][0].'';
$priority = '$_POST[priority]';
$sql = "SELECT * FROM flux_student_records WHERE studentname = '$fullname' ";
$retval = mysql_query($sql) or die(mysql_error());
if (!$retval) {
die('Could not retrieve data: There are no project proposals yet. <br /><br /> ' . mysql_error()); }
while ($row = mysql_fetch_array($retval)) {
extract($row); }
$sql = "INSERT INTO flux_project_selection( id, studentname, title, academicdiscipline, priority)
SELECT flux_student_records.id, flux_student_records.studentname, project_proposals.title, project_proposals.academicdiscipline, '$priority'
FROM project_proposals
JOIN flux_student_records ON project_proposals.academicdiscipline = flux_student_records.academicdiscipline
WHERE flux_student_records.studentname = '$studentname'
AND 'priority' IS NOT NULL
LIMIT 5";
$retval = mysql_query($sql) or die('Error: MySQL query failed. Project has not been added to the database. ');
echo "<p> Your project selection have been added to the system. <br> You'll be redirected to list of projects in the system. </p><br />";
//echo "<meta http-equiv=Refresh content=2;url=index.php>";
}
答案 0 :(得分:6)
我可以从你在问题中发布的代码中看出,你不是在PHP中
<form name=\"projects\" action=\"upload.php\" method=\"POST\">
所以从所有这些中删除斜杠\
。
然后这些:
if(isset($_POST[submit]) && !empty($_POST[submit])) {
$priority = '$_POST[priority]';
您需要添加和删除引号:
if(isset($_POST['submit']) && !empty($_POST['submit'])) {
$priority = $_POST['priority'];
此外,您的所有<option>
都没有为其设置值,因此您可能想要对此做些什么。
即:<option value=\"1\"> 1 </option>
等
另外,使用mysql_
函数删除。它们已被弃用,将从未来的PHP版本中删除。
使用mysqli
with prepared statements或PDO with prepared statements。 他们更安全。
我尝试过使用PHP_SELF ...
如果不在PHP中,你可以使用action=""
,这与self相同。或者,action=\"\"
如果在PHP内部,或action=''
,取决于你如何回应它。
将error reporting添加到文件的顶部,这有助于查找错误。
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// rest of your code
旁注:错误报告应仅在暂存时完成,而不是生产。
修改强>
我在您的查询中注意到的另一件事:
$sql = "INSERT INTO flux_project_selection( id, studentname, title, academicdiscipline, priority)
SELECT flux_student_records.id, flux_student_records.studentname, project_proposals.title, project_proposals.academicdiscipline, '$priority'
FROM project_proposals
JOIN flux_student_records ON project_proposals.academicdiscipline = flux_student_records.academicdiscipline
WHERE flux_student_records.studentname = '$studentname'
AND 'priority' IS NOT NULL
LIMIT 5";
尝试从'$priority'
和AND 'priority'
删除引号,因为它看起来像是一列。
如果$priority
包含MySQL可能会抱怨的任何字符,请使用mysql_real_escape_string()
将其换成刻度而不是引号并转义变量。
即:
project_proposals.academicdiscipline, `$priority`
FROM project_proposals
...
AND `priority` IS NOT NULL
这也对你没有帮助
$retval = mysql_query($sql) or die('Error: MySQL query failed. Project has not been added to the database. ');
使用or die(mysql_error());
代替or die('Error: MySQL query failed. Project has not been added to the database. ');
答案 1 :(得分:1)
修改
<form name=\"projects\" action=\"upload.php\" method=\"POST\">
到
<form name="projects" action="upload.php" method="POST">
或将其放在echo
中也
$priority = '$_POST[priority]';
这会将$_POST[priority]
作为字符串放在变量$priority
将其更改为:
$priority = $_POST['priority'];