我无法上传到数据库下拉菜单变量,当表单提交时文本区域为空白。我是编码新手,到目前为止我找到的所有信息都无法帮助我。学生的名字和姓都正在提交,我现在需要处理他们的成绩
这些是主题:
English<br>
<select name="Grade">
<option value="-">-</option>
<option value="A*">A*</option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="Fail">Fail</option>
</select><br>
Maths<br>
<select name="Grade2">
<option value="-">-</option>
<option value="A*">A*</option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="Fail">Fail</option>
</select><br>
Science<br>
<select name="Grade3">
<option value="-">-</option>
<option value="A*">A*</option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="Fail">Fail</option>
</select><br>
我需要将它们上传到这里:
$DB_HOST = "localhost";
$DB_USERNAME = "admin";
$DB_PASSWORD = "chichester";
$DB_NAME = "results";
$fname = $_POST["fname"];
$lname = $_POST["lname"];
$examboard = $_POST["examboard"];
$grade = $_POST["grade"];
$grade2 = $_POST["grade2"];
$grade3 = $_POST["grade3"];
$additionalcomments = $_POST["Additional Comments"];
$conn = new mysqli($DB_HOST, $DB_USERNAME, $DB_PASSWORD, $DB_NAME);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO studentresults (Name,lastname,examboard,additionalcomments) VALUES ('$fname','$lname','$examboard','$grade','$grade2','$grade3','$additionalcomments')";
$sql = "INSERT INTO studentresults (grade, grade2, grade3) VALUES ('$grade','$grade2','$grade3')";
if ($conn->query($sql) === TRUE) {
echo "Student exam results have been successfully submitted. ";
} else {
echo "Error, please try again later. : " . $sql . "<br>" . $conn->error;
}
//close connection
$conn->close();
现在我如何克服这个问题,脚本和数据库不显示错误。我需要做的就是处理一系列考试结果并将其显示在数据库中。标签似乎让事情变得混乱。
答案 0 :(得分:0)
1)您正在更新插入查询。
2)您编写的查询错误,因为列数与给定值的数量不同。
3)$_POST["Additional Comments"];
这不起作用,因为数组键不能包含空格。
答案 1 :(得分:0)
为什么你有两个$ sql insert语句?只使用一个。
plugins/image.min.css
$ _POST中不能有空格[&#39;&#39;];变量