三个相关表:一个表是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!";
}