我为不同的文章创建了一个评论框。
数据库名称为test
**INSERT INTO `test`.`test` (`id`, `name`, `email`, `comment`, `timestamp`, `articleid`)**
和评论文件名是formcode.php,代码是
**<form method='post'>
NAME: <input type='text' name='name' id='name' /><br />
Email: <input type='text' name='email' id='email' /><br />
Comment:<br />
<textarea name='comment' id='comment' /></textarea><br />
<input type='hidden' name='articleid' id='articleid' value='<?php echo $_GET["id"]; ?>' />
<input type='submit' value='Submit' />
</form>**
并且必须提交一个是manage_comments.php 代码在这里
**<?php
if( $_POST )
{
$con = mysql_connect("localhost","asim","1234");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);
$users_name = $_POST['name'];
$users_email = $_POST['email'];
$users_comment = $_POST['comment'];
$users_name = htmlspecialchars($users_name);
$users_email = htmlspecialchars($users_email);
$users_comment = htmlspecialchars($users_comment);
$articleid = $_GET['id'];
echo $id;
if( ! is_numeric($articleid) )
die('invalid article id');
$query = "
INSERT INTO `test`.`test` (`id`, `name`, `email`,
`comment`, `timestamp`, `articleid`) VALUES (NULL, '$users_name',
'$users_email','$users_comment',
CURRENT_TIMESTAMP, '$articleid');";
mysql_query($query);
echo "<h2>Thank you for your Comment!</h2>";
mysql_close($con);
}
?>**
和其他文件是display_comments.php,代码是
**<?php
$con = mysql_connect("localhost","asim","1234");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);
$article_id = $_GET['id'];
if( ! is_numeric($article_id) )
die('invalid article id');
$query = "SELECT * FROM `test` WHERE `articleid` =$article_id LIMIT 0 , 30";
$comments = mysql_query($query);
echo "<h1>User Comments</h1>";
while($row = mysql_fetch_array($comments, MYSQL_ASSOC))
{
$name = $row['name'];
$email = $row['email'];
$comment = $row['comment'];
$timestamp = $row['timestamp'];
echo " <div style='margin:30px 0px;'>
Name: $name<br />
Email: $email<br />
Comment: $comment<br />
Timestamp: $timestamp
</div>";
}
mysql_close($con);
?>**
我有不同的文章。 但我无法在url中获取查询值 是的
例如path
**http://localhost/mysite-Copy/category/Article/money1.php**
但它没有为文章ID设置查询值 有什么问题帮我PLZ
答案 0 :(得分:0)
使用$_POST['articleid']
代替$_GET['id']
。因为表单方法是'post'
。例如,还要为文章ID 12添加?id=12
到url。