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>