3
So guys, I wanted to rescue the data to edit on update.php
, but I’m a little lost here, it’s got to give?
<div class="container">
<div class="table-responsive">
<table class="table">
<tr>
<th>Produtos</th>
<th>Marca</th>
<th>Modelo</th>
<th>Quantidade</th>
<th>Estado</th>
<th>Opções</td>
</tr>
<?php foreach ($resultado as $key) :?>
<tr>
<td><?php echo $key->nome;?></td>
<td><?php echo $key->marca;?></td>
<td><?php echo $key->modelo;?></td>
<td><?php echo $key->quantidade;?></td>
<td><?php echo $key->estado;?></td>
<td>
<a href="mysql/update.php?id=<?php echo $key->id; ?>">Alterar</a>
<a href="mysql/delete.php?id=<?php echo $key->id; ?>">/Deletar</a>
</td>
</tr>
<?php endforeach;?>
</table>
</div>
update php.
<?php try{ $id = $_GET['id']; $sql = $pdo->prepare("UPDATE FROM estoqueprodutos . produtos WHERE id = $id"); $sql->execute(); var_dump($id); echo $sql->rowCount(); }catch (PDOException $e){ echo 'Error: '. $e->getMessage(); } ?>
EDITED
Guys I’m having a problem I created this code to get leaner but it’s not running and it’s not giving me any error you could help me to solve this problem?
if(!empty($_POST['id'])){
try {
$sql = "update produtos set nome = ?, marca = ?, modelo = ?, quantidade = ?, estado = ? where id = ?";
$statement = $pdo->prepare($sql);
$statement->bindParam(1, $_POST['nome']);
$statement->bindParam(2, $_POST['marca']);
$statement->bindParam(3, $_POST['modelo']);
$statement->bindParam(4, $_POST['quant']);
$statement->bindParam(5, $_POST['estado']);
$statement->bindParam(6, $_POST['id']);
$statement->execute();
var_dump($statement);
} catch (PDOException $e) {
print $e->getMessage();
}
} else {
echo "Desculpe-nos, mas não foi possível alterar este produto. Entre em contato com o suporte!";
}
?>
What’s the doubt? From PHP and PDO I don’t know what you’re asking, but it would be nice to at least read the SQL manual to see the UPDATE syntax.
– Bacco
That’s almost it, just need to create the inputs with the values of the bank and use Prepared statements correctly.
– rray
i want to rescue table data by id and edit in my update.php but I’m lost on that.
– felipe marques
@felipemarques would be nice if you [Dit] the question and put this information, and all possible details of the difficulty you are having, otherwise it becomes a guessing game. Suggested reading: [Ask]
– Bacco
Make a select by specifying the
id
, and executes theupdate
when the form is submitted.– Edilson
@felipemarques if it is a different question, ask a new question separately from this one. If there is no error, it may be that the ID is going empty, then it doesn’t even try to update; You need to check the FORM that sends this data.
– Bacco