php mysql pdo从表单输入插入相关表

时间:2013-09-23 18:45:31

标签: mysql pdo insert

三个相关表:一个表是member表,能够添加到另外两个表中(实际上其中一个表是一个名为location表的zip / city / state,所以无需插入),但第三个表格为postad,其中会员可以发布广告。

成员已登录并且会话已启动并且已定向到postad表单,该成员如何填充postad表。表格是:

member (id, username, email, address, locationId ...)
location (zip, state, county)
postad (id, title, descrip, locationId, memberId ...)

以下是代码:

$post=array('title','descrip','locationid','memberid');
foreach ($_POST as $post => $var) $$post=$var; 

if ($_POST['submitted']) {

$stmt = $pdo->prepare("INSERT INTO `postad` (`title`,`descrip`,`locationid`,`memberId`) VALUES 
(:title,:descrip,(SELECT `id` FROM `location` WHERE `id` LIKE :id AND `member.id`=:memberid))")

echo "Thank you!"; 

}

0 个答案:

没有答案