首先,MySQL_
不推荐使用 。使用MySQLi_
和/或 PDO。
现在,您没有指定"where"
将数据放入表中。
假设您的列分别命名subject
和comment
。
此外,这个词table
是一个保留 字。因此,如果您的表确实被称为table
,则需要在反引号内换行,
like this: `table`
$query = mysql_query("INSERT INTO table (`subject`, `comment`)
VALUES ('$subject','$comment')");
如果表名被称为“表”:
利用:
$query = mysql_query("INSERT INTO `table` (`subject`, `comment`)
VALUES ('$subject','$comment')");
从中删除'',
,('','$subject','$comment')
因为您在 DB 中只有 2 个值。
您甚至可能想要连接,例如:
VALUES ('" . $subject . "','" . $comment . "')");
要回显成功消息:
$query = mysql_query("INSERT INTO `table` (`subject`, `comment`)
VALUES ('$subject','$comment')");
echo "Data successfully written to DB";
}
else{
echo "Sorry, there was a problem.";
}
编辑2:
<?php
$subject = $_POST['subject'];
$comment = $_POST['comment'];
if(isset($_POST['submit']))
{
$connect = mysql_connect("host","un","psw");
mysql_select_db("rebeler_comment");
$query = mysql_query("INSERT INTO `table` (`subject`, `comment`) VALUES ('" . $subject . "','" . $comment . "')");
$retval = mysql_query( $query, $connection ); if(! $retval ) { die('Could not enter data: ' . mysql_error()); }
echo "Entered data successfully\n";
mysql_close($connection);
}
?>
编辑1:
$query = mysql_query("INSERT INTO `table` (`subject`, `comment`) VALUES ('" . $subject . "','" . $comment . "')");
$retval = mysql_query( $query, $connection ); if(! $retval ) { die('Could not enter data: ' . mysql_error()); }
echo "Entered data successfully\n";
mysql_close($connection);