我正在开发一个工作问题门户。现在我有一个问题,每个问题应该是一个按钮“添加到测试”。如果单击此按钮,则内容content-div
将保存到 MySQL 表中。我使用以下代码....
主要代码
<div id="content">
This content shut be safe in the MySQL table..
</div>
<script>
$(function(){
$('input.add').on('click',function(){
var div_contents = $("#content").html();
$.post('tomysql.php', { content: div_content });
});
});
</script>
<input type="button" class="add" value="Add to Test" />
tomysql.php
<?php
$con = mysql_connect('127.0.0.1', 'root');
mysql_select_db($teste, $con);
$div = mysql_real_escape_string($_POST['content']);
$sql = "INSERT INTO teste (content) VALUES ('{$div}')";
$query = mysql_query($sql, $con);
if($query) {
// Success!
} else {
// Failure :(
}
?>
但它现在不起作用。问题出在哪里?