I have the following structure:
<div class="username">
<label>Usuário: </label>
<p><?php echo $result[0]['username']; ?></p>
<a>Editar</a>
<input name="user" value="<?php echo $result[0]['username']; ?>" type="text">
<button>Salvar</button>
<span>Sucesso</span>
</div>
I am sending content from input user
to my php
:
$('div.username button').click(function() {
$.post("forms/editprofile.php?edit=username", $("div.username input").val(), function(retorno) {
if(retorno == "success") {
$("div.username span").show('250');
} else {
$("div.username span").val("Falha").show('250');
}
});
});
And in PHP
I update my registry with the received value:
<?php
require_once '../libs/minpdo.php';
session_start();
$mnpdo = new MinPDO();
$edit = $_REQUEST['edit'];
if($edit == "username") {
$user = $_REQUEST['user'];
try {
$mnpdo->update("users", "username", $user, "id = {$_SESSION['id']}");
echo "success";
} catch (MinPDOException $ex) {
echo "fail";
}
}
The message Success appears, but I go to the database and look at the record, in the field username
it is empty, probably the error is either passing the data or receiving:
To pass:
$.post("forms/editprofile.php?edit=username", $("div.username input").val(), function(retorno) ....
To receive:
$user = $_REQUEST['user'];
What would be my mistake?