0
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’m uploading the contents of input user
for 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 the PHP
i update my record with the amount received:
<?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 Success message is displayed, but I go to the database and look at the record, in the field username
it is empty, probably the error is either when passing the die or when 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?