0
I’m having trouble doing an update not working me I am using PDO. the queries works in prefection.
code I have in the script that receives the form data
<script>
function update() {
var data = {"func": "save"};
data = $("#editar").serialize() + "&" + $.param(data);
$.ajax({
type: 'POST',
url: "../Logica/info/info.php",
data: data,
success: function () {
alert("dados modificados com sucesso");
}
});
} ;
</script>
php code
$id= filter_input(INPUT_POST,'ID');
$observacoes= filter_input(INPUT_POST,'observacoes');
if (isset($_POST["func"]) && !empty($_POST["func"])) { //Checks if action value exists
$action = $_POST["func"];
switch($action) { //Switch case for value of action
case "save": editar($id,$observacoes);
break;
}
}
function editar($id,$observacoes){
$db = new ligacao();
$conn = $db->open();
$sql = "UPDATE INFO
SET OBS =$observacoes
WHERE id=$id";
$stmt = $conn->prepare($sql);
$stmt->execute();
}
is not updating me
When running in php,
print_r($_POST)
key appearsfunc
?– rray
yes appears I already found out... I was not receiving the id...because before I have a form but this id was not there because no one can know ...I will ask you to use a session variable... I already say if gave or not
– usersantos
in the form I created a hidden input to store the id that I will fetch the comic before, I have a select and put the information in a form.
– usersantos
That solved the problem?
– rray
yes solved the problem.. was not saving the id so it would never be sent to the sql server
– usersantos