如何使用MYSQL将此INSERT
语句转换为UPDATE
语句?表filmInfo
引用actorsInfo
的外键id_actor
表actorsInfo.id
。
可能是更好的方法,但这就是我现在所拥有的。
$sql="INSERT INTO filmInfo (filmTitle, filmRole, filmDirector, id_actor)
VALUES
('$_POST[filmTitle]','$_POST[filmRole]','$_POST[filmDirector]',
( select id FROM actorsInfo WHERE email = '$_SESSION[email]'))";
这是我的查询。
$query="SELECT filmTitle, filmRole, filmDirector, idfilm FROM filmInfo, actorsInfo
WHERE (actorsInfo.id = filmInfo.id_actor) AND email = '$_SESSION[email]'";
我试过了,但UPDATE
不起作用:
$sql= "Update filmInfo join actorsInfo
ON actorsInfo.id = filmInfo.id_actor
Set
filmTitle = '$filmTitle',
filmRole = '$filmRole',
filmDirecto = '$filmDirector'
WHERE (actorsInfo.id = afillInfo.id_actor) AND email = '$_SESSION[email]'";
请帮忙!
答案 0 :(得分:1)
这应该这样做:
$sql= "Update filmInfo join actorsInfo
ON actorsInfo.id = filmInfo.id_actor
Set
filmTitle = '$filmTitle',
filmRole = '$filmRole',
filmDirecto = '$filmDirector'
WHERE email = '$_SESSION[email]'";
您在afillInfo.id_actor
中引用了WHERE
,但查询中没有提到这样的表格。所有加入条件都应在ON
条款中。