我在网站上的某个地方添加了以下内容:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Comment system using php and mysql</title>
</head>
<body>
<?php
mysql_connect("localhost", "root", "")or die("cannot connect server ");
mysql_select_db("comments")or die("cannot select DB");
?>
<form name="comment" method="post" action="comment.php" onSubmit="return validation()">
<table width="500" border="0" cellspacing="3" cellpadding="3" style="margin:auto;">
<tr>
<td align="right" id="one">Name :<span style="color:#F00;">*</span></td>
<td><input type="text" name="namename" id="tnameid"></td>
</tr>
<tr>
<td align="right" id="one"></td>
<td><textarea name="message" id="tmessageid"></textarea></td>
</tr>
<tr>
<td align="right" id="one"></td>
<td><input type="submit" name="submit" id="submit" value="Submit Comment"></td>
</tr>
</table>
</form>
</body>
</html>Comment.php看起来像tihs:
<?php
if(isset($_POST['submit']))
{
$name=$_POST['namename'];
$message=$_POST['message'];
$insert=mysql_query("insert into commenttable
(name, message)values
('$name','$message')")or die(mysql_error());
header("Location:index.php");
}
?>当我提交的时候,我没有选择任何数据库。我的数据库是"comments“,其中有一个表"commenttable”、"name“和"message”。
发布于 2014-05-07 20:34:17
如果您的超文本标记语言标记文件具有扩展名超文本标记语言,<?php ?>将如何工作?
将您的mysql_connect和mysql_select_db放入comment.php文件中。
https://stackoverflow.com/questions/23517880
复制相似问题