Why this does't work?
<form id='formprofile' autocomplete='off'>
<input type='text' name='name' value='<?php echo $row['name'];?>'>
<input type='text' name='sname' value='<?php echo $row['sname'];?>'>
<button type='button' id='btnsave'>Save</button>
</form>
javascript
$('#btnsave').click(function(){
$.ajax({
url: 'profilesave.php',
type: 'post',
data: $('#formprofile').serialize(),
success: function(data) {
if (data =='empty'){
alert ('something is missing!');
}
else{
alert ('profile saved');
location.href = 'index.php';
}
}
});
});
profilesave.php
extract($_POST);
if ($name == ''){
echo ('empty');
exit();
}
try {
$stmt = $db->prepare('UPDATE members SET name = :name, sname = :sname WHERE user = :"' . $user . '"');
$stmt->execute(array(
":name" => $name,
":sname" => $sname
));
}
catch(PDOException $e) {
echo $e->getMessage();
}
Database is not updated.
Variable $user
is tested, it exists and have a propper value.
Database is not updated.
Variable $user
is tested, it exists and have a propper value.