Php 我能';t将字符串值传递到数组中
我有这段代码,但无法传递数组变量$component的值,该变量的输入数据为string。我该怎么办Php 我能';t将字符串值传递到数组中,php,arrays,Php,Arrays,我有这段代码,但无法传递数组变量$component的值,该变量的输入数据为string。我该怎么办 <?php if(isset($_POST['submit_tbl_grade'])){ $id = isset($_POST['id']) ? $_POST['id'] : array(); $component = $_POST['component'];
<?php if(isset($_POST['submit_tbl_grade'])){
$id = isset($_POST['id']) ? $_POST['id'] : array();
$component = $_POST['component'];
$sub_component_number = $_POST['sub_component_number'];
$subject = $_POST['subject'];
$score = $_POST['score'];
for($i = 0 ; $i < count($id) ; $i++){
$record = "INSERT INTO tbl_grade(stud_id,subject_id,component,sub_component_number,component_value) VALUES ($id[$i],$subject[$i],$component[$i],$sub_component_number[$i],$score[$i])";
mysqli_query($db,$record);
}
} ?>
请先阅读并检查$\u POST数据,以确保您了解数据结构
示例代码中还有两个问题:
tbl_grade.component
定义为“varchar”,则必须用引号括起值,请检查以下示例
INSERT INTO `tbl_grade` ( `component` ) VALUES ("hello world");
检查表单html是什么样子的?