我正在尝试创建具有多个页面的评论系统(每个页面都有其自己的注释)。
例如 - 访问者的两页:alegro.php和darwin.php
alegro.php
<?php
$page="alegro"; // this variable should identify a page
include "comments.php";
?>
darwin.php
<?php
$page="darwin";
include "comments.php";
?>
comment.php具有评论信息和一些JS验证代码。
然后注释。php将全部发送到第四个文件-Spist.php,该文件填充DBTable:
mysql_query("INSERT INTO comments(page,name,url,email,body) VALUES (
'$page' // - this is my first try
$page // - the second try
'".$arr['page']."' //the third try (after implementing a hidden "page" field into the form).
'".$arr['name']."',
'".$arr['url']."',
'".$arr['email']."',
'".$arr['body']."'
)");
无论如何 - $page
值未写入表。
为什么要使用 $page
?
只是插入功能likie
function insertdata (){
// do your code of inserting here to database
}
,在每个文件darwin
或alegro
中只需包含此功能。
exempel
if (isset($_POST['submit_comment']))
{
function insertdata() ;
}
darwin.php
$page = 'darwin';
include('comments.php');
注释.php
<form action="submit.php">
<input type="hidden" name="page" value="<?php echo $page; ?>" />
<textarea name="comment"></textarea>
</form>
submit.php
// $arr array filled
$arr['page'] = $_REQUEST['page'];
mysql_query("INSERT INTO comments(page,name,url,email,body) VALUES (
'".$arr['page']."',
'".$arr['name']."',
'".$arr['url']."',
'".$arr['email']."',
'".$arr['body']."'
)");
fyi-不要使用mysql_*,因为它被弃用。切换到PDO或Mysqli功能。