this is my first time using jquery, and i dont think it seems to be working. here is some code…
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script type = "text/javascript">
function insertComment(comment, assignment, pid){
alert(comment);
alert(assignment);
alert(pid);
var url = "addComment.php";
$.post(url, {comment: comment, assignment: assignment, pid: pid});
}
</script>
heres addComment.php
<?php
include ("viewComments.php");
//Connection string to get to database
$host = 'host';
$user = 'user';
$password = 'pw';
$dbh = new mysqli($localhost, $user, $password, "kao17_CS242Portfolio");
//Prpared statement for user inpur, prevent sql-injection attacks
$stmt = $dbh->prepare("INSERT INTO tbl_Comment (comment, project_title, parent_comment_id) VALUES (? , ? , ?)");
$stmt->bind_param('ssi', $prevComment, $prevAssignment, $parentID);
$prevAssignment = $_POST['assignment'];
$parentID = $_POST['pid'];
$prevComment = profanityCheck($_POST['comment']);
$stmt->execute();
?>
its not doing anything. is there away to alert if it actually went to addComments? or am i just using post wrong (SQL should be right). i know i’m getting the information for the parameter right (alerts) any help would be great, thanks!
You can add a callback function to your call to
$.post:Then in your PHP add
die('OK')after you execute your SQL statement. If you getOKin an alert box when you runinsertCommentthen you know the call has been successful and any problem is with your PHP.