Skip to content

Commit

Permalink
Fim do CRUD com MySQL e PHP estruturado
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronneesley committed Aug 22, 2024
1 parent f4f38d5 commit 721f109
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 10 deletions.
18 changes: 18 additions & 0 deletions exemplos/php/crud/publicacao_animes/src/alterar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

$id = $_POST["id"];
$titulo = $_POST["titulo"];
$sinopse = $_POST["sinopse"];

$con = new mysqli("localhost", "root", "", "publicacao");

$con->query("update animes set titulo = '$titulo',
sinopse = '$sinopse' where id = $id");

$con->close();

echo "Alterado com sucesso";

?>

<a href="listagem.php">Listagem</a>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</head>

<body>
<h1>Cadastro de Animes</h1>
<h1>Cadastro de Animes</h1>

<form action="inserir.php" method="post">
<div class="campo">
Expand Down
49 changes: 49 additions & 0 deletions exemplos/php/crud/publicacao_animes/src/editar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

$id = $_GET["id"];

$con = new mysqli("localhost", "root", "", "publicacao");

$res = $con->query("select * from animes where id = $id");

if ($linha = $res->fetch_object()){
$id = $linha->id;
$titulo = $linha->titulo;
$sinopse = $linha->sinopse;
$dataCadastro = $linha->data_cadastro;


}

$con->close();

?>

<!DOCTYPE html>
<html>
<head>
<title>Editar Anime</title>

<link rel="stylesheet" href="css/form.css" />
</head>

<body>
<h1>Editar de Anime</h1>

<form action="alterar.php" method="post">
<input type="hidden" name="id" value="<?=$id?>" />

<div class="campo">
<label>T&iacute;tulo</label>
<input type="text" name="titulo" value="<?=$titulo?>" />
</div>

<div class="campo">
<label>Sinopse</label>
<textarea cols="50" rows="5" name="sinopse"><?=$sinopse?></textarea>
</div>

<input type="submit" value="Salvar" />
</form>
</body>
</html>
4 changes: 3 additions & 1 deletion exemplos/php/crud/publicacao_animes/src/excluir.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@

echo "Excluído com sucesso";

?>
?>

<a href="listagem.php">Listagem</a>
5 changes: 5 additions & 0 deletions exemplos/php/crud/publicacao_animes/src/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

header("Location: listagem.php");

?>
6 changes: 4 additions & 2 deletions exemplos/php/crud/publicacao_animes/src/inserir.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

$con->close();

echo "Salvo com sucesso";
echo "Inserido com sucesso";

?>
?>

<a href="listagem.php">Listagem</a>
17 changes: 11 additions & 6 deletions exemplos/php/crud/publicacao_animes/src/listagem.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<h1>Listagem de Animes</h1>

<a href="cadastro.html">Incluir novo anime</a>

<table border="1">
<thead>
<tr>
<th>Título</th>
<th>Sinopse</th>
<th></th>
<th>Opções</th>
</tr>
</thead>

Expand All @@ -17,11 +19,14 @@
$res = $con->query("select * from animes order by titulo");

while ($linha = $res->fetch_object()){
echo "<tr>";
echo "<td>" . $linha->titulo . "</td>";
echo "<td>" . $linha->sinopse . "</td>";
echo "<td><a href='excluir.php?id=$linha->id'>Excluir</a></td>";
echo "</tr>";
echo "<tr>\n";
echo "<td>" . $linha->titulo . "</td>\n";
echo "<td>" . $linha->sinopse . "</td>\n";
echo "<td>\n";
echo "<a href='editar.php?id=$linha->id'>Editar</a> ";
echo "<a href='excluir.php?id=$linha->id'>Excluir</a>";
echo "</td>\n";
echo "</tr>\n";
}

$con->close();
Expand Down

0 comments on commit 721f109

Please sign in to comment.