我创建了迷你内容管理系统。现在得到了当场打死问题一次向多个MySQL表中插入值
我用下面的函数
function filter($data, $db)
{
$data = trim(htmlentities(strip_tags($data)));
if (get_magic_quotes_gpc())
$data = stripslashes($data);
$data = $db->escape_string($data);
return $data;
}
而且PHP代码过滤帖子看起来像
$name=filter($_POST['name'], $db);
$title=filter($_POST['title'], $db);
$parent=filter($_POST['parent'],$db);
$switch=filter($_POST['switch'], $db);
if($switch=''){
echo "Return back and select an option";
die();
}
$parentcheck=filter($_POST['parentcheck'],$db);
if($parentcheck=='0')
{
$parent=$parentcheck;
}
$purifier = new HTMLPurifier();
$content = $db->real_escape_string($purifier->purify($_POST['content']));
if(isset($_POST['submit'])&&$_POST['submit']=='Ok'){
$result=$db->query("INSERT INTO menu (parent, name, showinmenu) VALUES ('$parent', '$name', '$switch'") or die($db->error);
$result2=$db->query("INSERT INTO pages (id, title, content) VALUES ('<what?>', '$title', '$content'") or die($db->error);
}
这就是我的表看起来怎么样命名
表“pages”
和 “菜单”
我的问题是如下:
我试图让自动递增
id
值从menu
表后('$parent', '$name', '$switch'")
插入并将此id
inpages
表 插入时($ title,$ content)。怎么做?是否可以使用单个 查询?$content
的值是带有HTML标签的文本。我正在使用html净化器。 我可以在插入数据库表之前过滤它的值吗?任何 建议/建议?
你在寻找mysql_insert_id()函数吗? –