Friday, 9 August 2013

Cannot post to a php file using post

Cannot post to a php file using post

I am trying to take the value from a textarea and post it to another PHP
file so that i can store it in the database. But the statement
$.post("insert.....") does not work.
function post() {
var cm = document.getElementById("comment").value;
//var cm=$('#comment').val();
if (cm == "") alert("Enter text before submitting");
else {
document.getElementById("comment").value = "";
$.post("insert.php", {
comment: cm
});
alert("inserting");
}
}
the php file
<?php
$cm=$_POST['comment'];
$con=mysql_connect("localhost","root","#death123#","");
date_default_timezone_set('Asia/Kolkata');
$db=mysql_select_db("connect_login_details",$con);
$d=date('Y').":".date('m').":".date('d');
$t=date('G').":".date('i').":".date('s');
$name=$_COOKIE["username"];
$result="INSERT INTO guestbook VALUES('$name','$cm','$d','$t')";
if(!mysql_query($result,$con))
echo '<script>alert("cant insert");</script>';
mysql_close($con);
?>

No comments:

Post a Comment