请帮助我从表格和动态文本字段中获取行,然后将其插入另一个表格。我想做的是从下表中获取一些特定的 state_id,结合<input type='text' name='constituency[]' />
同一页面上显示的文本框中的数据,然后插入到表中
+---------+--------------------------+
|state_id | state | senatorial |
|--- -----|----------|---------------|
| 1 | utah | A-North |
| 2 | utah | B-South |
+---------+----------+---------------+
我用来获取信息的 HTML。选区是一个动态文本字段,并且出现多次,因此需要将它放在一个数组中
<input type='hidden' name="state_id[]" value="<?php echo $row['state_id'];?>" />
<input type='text' name='constituency[]' />
我用来插入表的查询
<?php
$constituencys = $_POST['constituency'] ;
$state_id = $_POST['state_id'];
if(isses($_POST['constituency']))
{
$constituencys = $_POST['constituency'] ;
foreach($constituencys as $constituency) {
$state_id[$i]= $state_id[$i];
$query = mysql_query("
INSERT INTO `constituency` (
`constituency_id`,
`state_id`,
`constituency_name`
) VALUES (
NULL,
'".$state_id[$i]."',
'".$constituency."'
");
}
if(mysql_affected_rows()>0){
echo "Inserted Successfully";
}else{
echo "No Row Inserted";
echo mysql_error() ;
echo"<br>Error:".mysql_error();
echo"<br>Query:".$query;
} } ?>
我要插入的表看起来像这样
+----------------+-------------+----------------------+
|constituency_id | state_id | constituency_name |
+----------------+----- -----+----------------------+
当我运行代码“No Row Inserted”显示在屏幕上
请帮我。我非常感谢,谢谢。
显示错误
Error: You have an error in your mysql syntax; check the manual that corresponds to your mysql server for the right syntax to use near " at line 2
Query: