1
I have a problem with a php script. The name attribute of a page receives a value that is generated by an array. What I need to do is basically generate a table in which each row has a button that serves to delete the same information received from the database, this button is the one that uses the attribute name to save the id of the received record. So I don’t know what I put on the other php page to save this value. I’ll put the code below for further analysis.
The bottom php page that shows the elements on the screen.
<?php
$query = sprintf("SELECT conteudo, autor, titulo, pagina, id FROM atualizacoes ORDER BY id DESC");
$dados = mysql_query($query, $con) or die(mysql_error());
$linha = mysql_fetch_assoc($dados);
$total = mysql_num_rows($dados);
?>
<body>
<div class="row ">
<div class="col-md-8 col-md-offset-2">
<form name="login" method="post" action="../removendo.php">
<h2 style="color: white">Atualizando blog</h2>
<table class="tabelaconteudo">
<?php
if($total>0){
do{
?>
<tr>
`<td><?= $linha['titulo']?></td>
<td><?= $linha['pagina'] ?></td>
<td><?= $linha['autor'] ?></td>
<td><input type="submit" class="btn-cad" style="color: white" value="Apagar"
name="ref_<?= $linha['id'] ?>"></td> //AQUI É O CAMPO O QUAL NÃO CONSIGO SALVAR A INFORMAÇÃO
</tr>
<?php
}while ($linha = mysql_fetch_assoc($dados));
}
?>
</table>
</form>
</div>
</div>
</body>
Below is the php page that is loaded when you press the Submit button (same as I cannot define a specific name).
<?php
error_reporting (E_ALL & ~ E_NOTICE & ~ E_DEPRECATED);
$id=$_POST['NAME QUE NAO ESTA DEFINIDO'];
$restid = substr($id, 1, 4);
$sql = mysql_query("DELETE FROM atualizacoes WHERE id = $restid");
echo"
<script>
document.getElementById('loader').onpageshow = alertfunc();
function alertfunc() {
alert('Ocorreu algum erro.'$sql);
}
</script>
";
?>
I started with web programming a short time ago, and all I’ve learned from php so far is this. I’ve swept the entire internet behind it and never found anything concrete until now, then in despair I come here for help. I would like to thank all those who have been willing to help.
Thank you very much I tested your solution and I managed to solve my problem!! Thank you very much!!! :)
– Evandro Machado Pereira