i know how to post data using javascript but im trying to work out how i can retrieve the last inserted row in a mysql table.
So i can use it in my success result.
Below is what i have so far but all it does is create the entry , i really want to direct the user to a page where they can now edit their new entry without having them click a button to go there first.
The code below has not got the part i really need, i just put it up so you can see my structure of what i am doing.
$("#CREATEDOCUMENT").click(function() {
var txt = $.ajax({
url: 'create_doc_entry.php',
async: true,
type:'POST',
data:({
usr_id:$('input#usr_id').val(),
})
}).success;
$('.pleasewait').fadeIn('slow');
setTimeout(function(){window.location="index.php?v=editdoc&id="+id;}, 2000);
});
As you can see from the above in the window.location url i have +id
I would really love that +id to be my last inserted id which i grab from the create_doc_entry.php file if you know what i mean.
Thanks in advance
John
First you will need to modify
create_doc_entry.phpso that it prints the last inserted ID after the INSERT.Then you probably should add the
successsetting in your ajax request, like this:So you can parse or do whatever you want with
datain thesuccessfunction.