【发布时间】:2014-06-24 08:56:55
【问题描述】:
我的代码
<?php
require('connect.php');
$name=$_POST['name'];
$comment=$_POST['comment'];
$submit=$_POST['submit'];
if($submit){
if($name&&$comment) {
$insert=mysql_query("INSERT INTO comment (name,comment) VALUES ('$name','$comment')");
}
else {
echo" please fill out the fields";
}
}
?>
<html>
<head>
<title>
The comment box
</title>
</head>
<body>
<form action="mainpage.php" method="POST">
<table>
<tr><td>Name:</td><td><input type="text" name="name"/></td></tr>
<tr><td colspan="2">Comment:</td></tr>
<tr><td colspan="2"><textarea name="comment"></textarea></td></tr>
<tr><td colspan="2"><input type="submit" name="submit" value="comment"/></td></tr>
</table>
</form>
</body>
</html>
这是非常简单的代码,当我打开文件时出现以下错误:
但是在我在 textarea 中添加一些东西后它们消失了,但是插入的数据没有进入数据库。
Notice: Undefined index: name in C:\xampp\htdocs\test\mainpage.php on line 5
Notice: Undefined index: comment in C:\xampp\htdocs\test\mainpage.php on line 6
Notice: Undefined index: submit in C:\xampp\htdocs\test\mainpage.php on line 7
请帮助我尝试了所有方法。
【问题讨论】:
-
a) 该代码本身易受 SQL 注入攻击 b) 您实际上是在
connect.php中打开连接还是仅包含必要的类/函数? -
另外:您当前分别在输入和文本区域输入什么文本来测试代码?
标签: php mysql database comments textarea