I’m trying to post some data to a function that will do a mysql insert. Nothing fancy about that. but I can get the thing to work and my question is where should I be telling jQuery to post to and will it honor php includes?
This is what I have
include_once 'modules/interviews/helper.php';
if($link == 'my_interviews'){
include_once 'modules/interviews/my_interviews.php';
} elseif($link == 'interview_panel'){
include_once 'modules/interviews/interview_panel.php';
}
Above is my index.php, which loads in the page where the form is submitted
$('.addinote').click(function() {
var app = $(this).attr("data-app"),
user = $(this).attr("data-subi"),
txt = $('#' + app).val();
if(txt === ''){
alert('Whoops, did you enter something?');
}else{
var params = {};
params['user_id'] = user;
params['app_id'] = app;
params['inote'] = txt;
params['subinote'] = '1';
$.post('http://localhost/gem/modules/interviews/index.php', params,
function(data){
if(data){
}
else{
alert('Whoops, there was a problem, please try again!');
}
});
}
helper.php contains this…
if(isset($_POST['subinote'])){
$apply->inote();
}
and the class contains this….
function inote(){
$query = "INSERT INTO `app_notes` (`user_id`, `application_id`, `inote`)
VALUES ('{$_POST['user_id']}', '{$_POST['app_id']}',
'{$_POST['inote']}')";
$GLOBALS['DB']->insertQuery($query);
}
Where should I be posting to?
You should be posting to index.php if this is the one reading the $_POST variable.
Also you should be using relative url’s for example if helper.php is in the same directory as your html file use
./index.phpor simplyindex.phpas your post url. I prefer the former as it states explicitly what you intended.