2
If you search only one like this and run the foreach it does the update but if you have more it no longer does... But if there’s more of one like in the other image it doesn’t change and it doesn’t make a mistake what I do?
Why not update ? ... It not of error none at all does not update
//Prepra ligacao php mysql
$stm = $pdo->prepare('SELECT * FROM sol_camiseta
WHERE cod_nome_aluno = :id' );
//Atribui o paramentro ao $_GET['id'] que é o id que esta na url e coloca ele no prepare acima
$stm->bindValue( ':id', $_GET['id'] );
//Executa o pdo
$stm->execute();
//Tranforma o consulta em matriz
$consultas = $stm->fetchAll( PDO::FETCH_ASSOC );
include 'views/listar.php';
<?php
error_reporting(E_ALL);
require 'conexao.php';
//Pega o id da url
if ( isset( $_GET['id'] ) && ! empty( $_GET['id'] ) ){
if ( $_POST ) {
//Ligação php mysql
$stm = $pdo->prepare( "UPDATE sol_camiseta
SET data_pagamento = :data_pagamento,
data_retirada = :data_retirada
WHERE id = :id");
//Atribui o paramentro ao $_POST['e a referecia onde ele esta'] e coloca ele no prepare acima
$stm->bindValue( ':data_pagamento', $_POST['data_pagamento'] );
$stm->bindValue( ':data_retirada', $_POST['data_retirada'] );
$stm->bindValue( ':id', $_GET['id'] );
//Executa o pdo
$stm->execute();
//depois de executar o header o rediciona para outro local
header( "Refresh:5, index.php" );
}
}
<fieldset>
<legend>Camiseta</legend>
<table>
<?php foreach ( $consultas as $consulta ) : ?>
<form action='pagarcamiseta.php?id=<?php echo $consulta['id']; ?>' method='post'>
<tr>
<td>Tipo:</td>
<td><?php echo $consulta['tipo']; ?></td>
<td>Cor:</td>
<td><?php echo $consulta['cor']; ?></td>
<td>Tamanho</td>
<td><?php echo $consulta['tamanho']; ?></td>
<td>Quantidade</td>
<td><?php echo $consulta['qtd']; ?></td>
<td>Valor</td>
<td><?php echo $consulta['valor']; ?></td>
</tr>
<tr>
<td>Data Pedido:</td>
<td><?php echo $consulta['data_pedido']; ?></td>
</tr>
<tr>
<td>Data Pagamento:</td>
<td><input type='date' name='data_pagamento' value='<?php if ( isset( $_POST['data_pagamento'] ) ) echo $_POST['data_pagamento']; else echo $consulta['data_pagamento']; ?>'></td>
<td>Data Retirada:</td>
<td><input type='date' name='data_retirada' value='<?php if ( isset( $_POST['data_retirada'] ) ) echo $_POST['data_retirada']; else echo $consulta['data_retirada']; ?>'></td>
<td><input type="submit" value="Salvar" /></td>
</tr>
<?php endforeach; ?>
<td><a href='index.php'>Voltar</a></td>
</table>
</fieldset>
</form>
Include a
error_reporting(E_ALL);
at the beginning of the script, some error should appear.– gustavox
At first just after <php? ?
– Victor Mansolelli
Yeah, at the beginning right after the
<?php
.– gustavox
No error has appeared
– Victor Mansolelli
It runs FOREACH but if it has two it no longer does the update
– Victor Mansolelli
But is it connecting with the bank? You need to catch the error ... At this link you can see how to catch connection error with PDO.
– gustavox
Worse than it is not giving error in connection...
– Victor Mansolelli
You saw the image I put there and I want that when I click on the save it changes the dates according to what I put... what you advise me?
– Victor Mansolelli
What I don’t understand is the cod_student name... it is part of the table sol_t-shirts right? But it is the primary key of the table?
– Andrei Coelho
So man, I don’t know about PDO, I use mysqli, but try to put
if (!$stm) {
 echo "\nPDO::errorInfo():\n";
 print_r($dbh->errorInfo());
}
or$stm -> setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
to see if there are any errors... fountain– gustavox
The primary key is the table ID
– Victor Mansolelli
I’ll try to put that
– Victor Mansolelli
place after
$stm->execute();
– gustavox
had an error in the first example, try so:
if (!$stm) { echo "\nPDO::errorInfo():\n"; print_r($pdo->errorInfo()); }
– gustavox
So comrade... the problem is there... you are making a looping that applies several Forms according to the amount of T-shirt per student id... you have to include the primary key in each form tbm so that when the person save the Pdo will know which record is... I think it is this
– Andrei Coelho
Check if the id to be changed exists and also see if the auto commit is turned on
– rray
So I changed the code yesterday... when I made it call by the id but then it only calls the first id and as if it included the first id, then all the lines idependente which save I click will be the first id of the foreach
– Victor Mansolelli