i am trying to post data to Mysql using jquery $.post and php page. my code is not running and nothing is added to the mysql table. I am not sure if the path i am creating is wrong but any help would be appreciated.
Jquery location: f_js/tasks/TaskTest.js
<script type="text/javascript">
$(document).ready(function(){
$("#AddTask").click(function(){
var acct = $('#acct').val();
var quicktask = $('#quicktask').val();
var user = $('#user').val();
$.post('addTask.php',{acct:acct,quicktask:quicktask,user:user}, function(data){
$('#result').fadeIn('slow').html(data);
});
});
});
</script>
addTask.php (runs the jqeury code)
<?php
include 'dbconnect.php';
include 'sessions.php';
$acct = $_POST['acct'];
$task = $_POST['quicktask'];
$taskstatus = 'Active';
//get task Creator
$user = $_POST['user'];
//query task creator from users table
$allusers = mysql_query("SELECT * FROM users WHERE username = '$user'");
while ($rows = mysql_fetch_array($allusers)) {
//get first and last name for task creator
$taskOwner = $rows['user_firstname'];
$taskOwnerLast = $rows['user_lastname'];
$taskOwnerFull = $taskOwner." ".$taskOwnerLast;
mysql_query("INSERT INTO tasks (taskresource, tasktitle, taskdetail, taskstatus, taskowner, taskOwnerFullName)
VALUES ('$acct', '$task', '$task', '$taskstatus', '$user', '$taskOwnerFull' )");
echo "inserted";
}
?>
Accountview.php finally the front page
<html>
<div class="input-cont ">
<input type="text" class="form-control col-lg-12" placeholder="Add a quick Task..." name ="quicktask" id="quicktask">
</div>
<div class="form-group">
<div class="pull-right chat-features">
<a href="javascript:;">
<i class="icon-camera"></i>
</a>
<a href="javascript:;">
<i class="icon-link"></i>
</a>
<input type="button" class="btn btn-danger" name="AddTask" id="AddTask" value="Add" />
<input type="hidden" name="acct" id="acct" value="<?php echo $_REQUEST['acctname']?>"/>
<input type="hidden" name="user" id="user" value="<?php $username = $_SESSION['username']; echo $username?>"/>
<div id="result">result</div>
</div>
</div>
<!-- js placed at the end of the document so the pages load faster -->
<script src="js/jquery.js"></script>
<script src="f_js/tasks/TaskTest.js"></script>
<!--common script for all pages-->
<script src="js/common-scripts.js"></script>
<script type="text/javascript" src="assets/gritter/js/jquery.gritter.js"></script>
<script src="js/gritter.js" type="text/javascript"></script>
<script>
</html>
Firebug reponse:
Response Headers
Connection Keep-Alive
Content-Length 0
Content-Type text/html
Date Fri, 08 Nov 2013 21:48:50 GMT
Keep-Alive timeout=5, max=100
Server Apache/2.4.4 (Win32) OpenSSL/0.9.8y PHP/5.4.16
X-Powered-By PHP/5.4.16
refresh 5; URL=index.php
Request Headers
Accept */*
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Content-Length 13
Content-Type application/x-www-form-urlencoded; charset=UTF-8
Cookie PHPSESSID=6gufl3guiiddreg8cdlc0htnc6
Host localhost
Referer http://localhost/betahtml/AccountView.php?acctname=client%201
User-Agent Mozilla/5.0 (Windows NT 6.3; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0
X-Requested-With XMLHttpRequest