我从来没有处理过这样的事情,因为我对数据库和MySQLi相对较新,但这是一个问题(可能是问题)已经被困了几个小时。
现在,在我说之前,我知道在设计一个带有MySQLi的博客/ CMS网站,以便一遍又一遍地使用同一页面并使用?id=1
结束URI时,会更容易。
等等。但我一直在尝试做这项工作,生成包含帖子内容和生成唯一页面名称的独特PHP页面。
收集我所有内容的表单非常标准,并插入到我的表的各行中
(title, postcat, excerpt, full, metadesc, linkprefix, link, frontpagelink)
我的表单和初始MySQLi没有问题,因为内容存储在数据库中没问题。它只是将内容写入模板并保存哪个是问题。 MySQLi如下。
$data = new mysqli('blah blah blah');
if (mysqli_connect_errno()) {
echo 'Oops, connection error! Please try again later.';
exit;
}
$title = $_POST['title'];
$cat = $_POST['postcat'];
$exc = $_POST['excerpt'];
$full = $_POST['full'];
$meta = $_POST['metadesc'];
$lp = $_POST['linkprefix'];
$li = $_POST['link'];
$fpl = $_POST['frontpagelink'];
$postarray = array(
"{title}",
"{postcat}",
"{metadesc}",
"{full}"
);
$posted = array(
"$title",
"$cat",
"$meta",
"$full"
);
$post = "insert into blogposts (title, postcat, excerpt, full, metadesc, linkprefix, link, frontpagelink)
VALUES ('$title', '$cat', '$exc', '$full', '$meta', '$lp', '$li', '$fpl')";
if ($data->query($post)) {
echo "alert('Added');";
} else {
echo "alert('{$data->error}');";
}
// works fine up to here.
$postto = strtolower($cat);
//name of the template file
$tpl_file = "post-template.php";
//path to the directory at the server, where you store the template file.
$tpl_path = "/blogdev/";
//path to the directory where you will store the auto-generated page.
$post_path = "/blogdev/blog/$postto/";
$tpl = file_get_contents("$tpl_path$tpl_file");
$new_post = str_replace($postarray, $posted, $tpl);
$php_file_name = $li . 'php';
$current = getcwd();
$path = "../blog/'.$postto.'/";
chdir("$path");
$fp = fopen("$post_path$php_file_name", "w");
fwrite($fp, $new_post);
fclose($fp);
chdir($current);
mysqli_close($data);
我的模板页面包含了进程文件(如果有必要),通过php include,还包含页面周围的各种占位符,这些占位符在我的进程数组中定义
{title}, {post cat}
等等。以下示例部分。
<title>{title} - {postcat} Posts -</title>
我不希望任何人完全调试我的代码或类似代码,我只是寻找新手的指针 - 感谢所有人和任何可以提前帮助的人!