我正在尝试使用下拉列表创建一个页面,我希望用户添加他想要的电影院名称并通过 mysql 查询将其发送到数据库。
现在,这就是我从数据库中获取下拉列表的方法(这部分正在工作)
<select name="cinema_id" id="cinemaid">
<?php
require('../classes/cinema_class.php');
$cinemas = cinema::get_cinemas_name();
$cinema_id = $cinema['cinema_id'];
$cinema_name = $cinema['cinema_name'];
foreach($cinemas as $cinema)
{
$selected = '';
if( $cinema['cinema_id'] == $_GET['cinema_id'])
{
$selected = 'select="selected"';
}
echo "<option {$selected} >
{$cinema['cinema_name']}
</option>";
}
?>
</select>
这是要更新的mysql查询
<?php
$theaterid=$_POST['theaterid'];
$theatername=$_POST['theatername'];
$cinemaid=$_POST['cinemaid'];
if(empty($theatername)){
echo "Theater Name is a must";
}
else{
$update_movie=mysql_query("UPDATE `memoire`.`theater`
SET `theater_name`= '$theatername',`cinema_id`= '$cinemaid' //the $theatername is working, i think the $cinemaid is wrong
WHERE `theater_id`='$theaterid'");
if($update_movie)
{ echo "Add Succesfull";}
else
{ echo "error in registration".mysql_error(); }
}?>
我认为问题是如何调用下拉列表中的值并将其发送到更新
对了,页面打印:error in registrationCannot add or update a child row: a foreign key constraint failed ( memoire
. theater
, CONSTRAINT theater_ibfk_1
FOREIGN KEY ( cinema_id
) REFERENCES cinema
( cinema_id
) ON DELETE CASCADE ON UPDATE CASCADE)