私はphpの初心者です。多対多の関係を持つ2つのテーブルと、関係用の別のテーブルがあります。
外部テーブルを更新するたびに、エラーが発生します:
Cannot add or update a child row: a foreign key constraint fails (`wikiseda`.`genre_singer`, CONSTRAINT `genre_singer_ibfk_1` FOREIGN KEY (`f_singer_id`) REFERENCES `singers` (`singerid`) ON DELETE CASCADE ON UPDATE CASCADE);
これは私のコードです:
<?php
include('../db_inc.php');
define("UPLOAD_DIR",realpath(dirname(__FILE__)));
$singer_name =$_POST['singer_name'];
$singer_gender=$_POST['singer_gender'];
$singer_des=$_POST['singer_description'];
$singer_genre=$_POST['genre_list'];
$path = UPLOAD_DIR .'/musics/'.$singer_name;
if(!file_exists($path)){
mkdir($path,0777,true);
}
$sql ="INSERT INTO singers(singer_name,singer_gender,singer_description) VALUES ('$singer_name','$singer_gender','$singer_des')" ;
$singer_id = mysql_insert_id();
$sql2 =("INSERT INTO genre_singer(f_singer_id,f_genre_id) VALUES ('$singer_id','$singer_genre')");
$result=mysql_query($sql)or die(mysql_error());
$result2=mysql_query($sql2)or die(mysql_error());
if('$result'){
echo "insert successfully";
};
?>