I'm trying to insert a value generated by a PHP script using an ajax function into my database based on the current session. Below it's my ajax function to generate a new address:
<script>
function newaddress(){
$.ajax({
url:"newaddress.php", //the page containing php script
type: "POST", //request type
success:function(result){
document.getElementById('depositAddress').value = result;
alert("New address generated");
}
});
}
</script>
My question is, How to add the 'result' to the database using the current session running on the page? I thought something along the lines of
<?php
include_once 'dbh.inc.php';
$sql = "INSERT INTO users(BTCAddress) VALUES ('result') WHERE ('u_uid') = ($_SESSION['u_uid']);";
?>
The second php script was just rough working out. Do i need to use the post method? If so, How to get the result generated by the ajax javascript to post into the php file in order to save the address generated into the database 'user' where the session is equal to the current session running on the web page?. Sorry if i have waffled on or overcomplicated things. Any help would be greatly appreciated.