i have little trouble with updating database by ajax , but i couldnt make it to work. i dont know what im doing wrong.
here my php file (sendata.php)
<?php
if ( isset($_POST['register']) && $userid != 0)
{$register = $_POST['register'] ;
$sql2 =$db->setQuery("INSERT INTO .... ");
$db->query() ;
}
?>
and here my javascript code
$(document).ready(function() {
$('#register').click(function() {
$.ajax({
url: "sendata.php",
data: {
age: $('#age').val()
},
type: 'POST',
success: function(msg) {
alert("Data has been saved succefully");
$('#mydata').html("<b> age: </b>" + age);
}
});
return false;
});
});
what is heppening to me is when register button is clicked i get only the alert , that data is saved succefully but when i go to database and see , there is no record at all there. im doing something wrong ?
EDIT :
this my button
<input type="submit" id="register" name="register" value="Save my Data" />