weixin_33682790 2014-03-26 19:42 采纳率: 0%
浏览 33

ajax插入到mysql问题

I got a problem in ajax I can't add information on mysql so here's what I got:

a index.php file with a table form

<form  method="post" name="form" action="">
<textarea style="width:500px; font-size:14px; height:60px; font-weight:bold; resize:none;" name="content" id="content" ></textarea><br />
<input type="submit" value="Post" name="submit" class="submit_button"/>
</form>

and a insert.php file:

<?php
include('config.php');


$content=mysql_real_escape_string($_POST['content']);
$query=mysql_query("INSERT INTO chat(ChatId,ChatText) VALUES('','$content') ");
echo $content;

?>

I leave there the echo $content; because it helps to understand my problem. So... When i write something in my box and I click on submit to insert the information into my sql table It dosen't insert so I leave there the echo code because I'm sure the information reach to my insert.php file.. so I don't really understand why the information is not inserted because the information comes. Any help?

ajax part:

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    setInterval(function(){
    $("#ChatMessages").load("msgs.php");
    },1000);
});
</script>

<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$(".submit_button").click(function() {
var textcontent = $("#content").val();
var dataString = 'content='+ textcontent;
if(textcontent=='')
{
alert("Enter some text..");
$("#content").focus();
}
else
{
$("#flash").show();
$("#flash").fadeIn(400).html('<span class="load">Loading..</span>');
$.ajax({
type: "POST",
url: "insert.php",
data: dataString,
cache: true,
success: function(html){
$("#show").after(html);
document.getElementById('content').value='';
$("#flash").hide();
$("#content").focus();
}  
});
}
return false;
});
});
</script>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡等级和折扣规则
    • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
    • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
    • ¥15 gdf格式的脑电数据如何处理matlab
    • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
    • ¥100 监控抖音用户作品更新可以微信公众号提醒
    • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
    • ¥70 2048小游戏毕设项目
    • ¥20 mysql架构,按照姓名分表
    • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分