quinta-feira, 8 de dezembro de 2016

Formulário PHP - Inserir / Adicionar - Alterar / Editar - Deletar / Excluir

/* 1° criar uma pasta "ProjetoPHP" em C:\wamp64\www\ProjetoPHP */

/* 2° criar o banco "Projeto" no phpmyadmin */

/* 3° criar tabela usuario banco "Projeto" no phpmyadmin  */
/* usuario varchar(10)*/
/* senha varchar(10)*/

/* 4° cadastrar usuario banco "Projeto" no phpmyadmin  */
/* usuario: admin */
/* senha: 123 */

/* 5° criar conecta.php e salavar em C:\wamp64\www\ProjetoPHP */

<?php

$link = mysqli_connect("localhost","root", "")
or die("Não achei o mySql");
mysqli_select_db($link,"projeto")
or die ("Banco de Dados Indisponivel !!!");

?>

/* 6° Criar o index.html e salavar em C:\wamp64\www\ProjetoPHP */

<html>
<title> Exemplo Login </title>
<body background="telainicial.jpg" align="center" >
<form action="entrar.php" method="POST">
<h1> LOGIN PHP FATEC </h1>
<p>
<table border="1"align="center">
<tr>
<td>Usuario:<input type="text" name="usuario" size=20></td>
<td>Senha:<input type="password" name="senha" size=20></td>
<td><input type="submit" value="Login"></td></tr>
</table>
</form>
</body>
</html>

/* 7° Criar o entrar.php e salavar em C:\wamp64\www\ProjetoPHP */

<?php
include "conecta.php";
$usuario=$_REQUEST["usuario"];// REQUEST pega o nome da variavel na html
$senha=$_REQUEST["senha"];
$consulta="select * from usuario where usuario='$usuario'and senha='$senha'";
$resultado=mysqli_query($link,$consulta)or die("Erro no Select");
if (mysqli_num_rows($resultado)>0)
{
header('Location: clientes.php');
}
else
{
echo " Usuario ou Senha nao Cadastrado !!!<br>";
echo "<a href='index.html'>Voltar";

}
mysqli_close($link);
?>

/* 8° Criar Tabela clientes banco "Projeto" no phpmyadmin */
/* codigo int */
/* nome varchar(50)*/
/* endereco varchar(100) */
/* telefone(11)*/
/* email (100)*/

/* 9º Criar cliente.html e salavar em C:\wamp64\www\ProjetoPHP */

<html>
<title>Cadastro de Clientes</title>
<meta charset="UTF-8">
<body background="telainicial.jpg" align="center" >
<form method="post"action="gravar.php">
<h1>Cadastro de Clientes</h1>
<hr>
<table border="1" align="center">
<tr>
<td>Código:</td><td><input type="text" name="codigo"></td>
</tr>
<tr>
<td>Nome:</td> <td><input type="text" name="nome" size="50"></td>
</tr>
<tr>
<td>Endereco:</td> <td><input type="text" name="endereco" size="50"></td>
</tr>
<tr>
<td>Telefone:</td> <td><input type="text" name="telefone" size="11"></td>
</tr>
<tr>
<td>E-mail:</td> <td><input type="text" name="email" size="50"></td>
</tr>
</table>
<input type="submit" value="Gravar">
</form>
</body>
</html>

/* 10º Criar cliente.php e salavar em C:\wamp64\www\ProjetoPHP */

<html>
<title>Cadastro de Clientes</title>
<meta charset="UTF-8">
<body background="telainicial.jpg" align="center" >
<form method="post"action="gravar.php">
<h1>Cadastro de Clientes</h1>
<hr>
<table border="1" align="center">
<tr>
<td>Código:</td><td><input type="text" name="codigo"></td>
</tr>
<tr>
<td>Nome:</td> <td><input type="text" name="nome" size="50"></td>
</tr>
<tr>
<td>Endereco:</td> <td><input type="text" name="endereco" size="50"></td>
</tr>
<tr>
<td>Telefone:</td> <td><input type="text" name="telefone" size="11"></td>
</tr>
<tr>
<td>E-mail:</td> <td><input type="text" name="email" size="50"></td>
</tr>
</table>
<input type="submit" value="Gravar">
</form>

<div align="center">
<?php
include 'conecta.php';
$consulta="select * from clientes order by codigo";
$resultado=mysqli_query($link, $consulta) or die ("Erro de select");

echo "<table border=1>";
echo "<tr><td>CODIGO</td><td>NOME</td><td>ENDERECO</td><td>TELEFONE</td><td>EMAIL</td></tr>";
while($registro=mysqli_fetch_array($resultado))
{
echo "<tr><td>".$registro['codigo']."</td><td>".$registro['nome']."</td><td>".$registro['endereco']."</td><td>".$registro['telefone']."</td><td>"
.$registro['email']."</td><td><a href='alterar.html'>Alterar</a></td><td>
<a href='deletar.html'>Deletar</a></td></tr>";

}

mysqli_close($link);
?>
</div>
</body>
</html>

/* 9º Criar deletar.html e salavar em C:\wamp64\www\ProjetoPHP */

<html>
<title>Deletar Cliente</title>
<body background="telainicial.jpg" align="center" >
<h1>Deletar Cliente</h1>
<form action="deletar.php" method="post">
Digite o codigo do Cliente a ser excluido;
<input type="text" name="codigo" size=10<br>
<input type="submit" value="deletar">
</form>
</body>
</html>

/* 10º Criar deletar.php e salavar em C:\wamp64\www\ProjetoPHP */

<?php
include 'conecta.php';
$codigo=$_REQUEST['codigo'];
$deletar="Delete from clientes where codigo=$codigo";
$resultado=mysqli_query($link, $deletar)or die("Erro no delete");
header('location: clientes.php');

?>

/* 11º Criar alterar.html e salavar em C:\wamp64\www\ProjetoPHP */

<html>
<title>Alterar Dados Cliente</title>
<body background="telainicial.jpg" align="center" >
<h1>Alterar Dados Cliente</h1>
<form method="post"action="alterar.php">
<h1>Cadastro de Clientes</h1>
<hr>
<table border="1" align="center">
<tr>
<td>Digite Código a Alterar:</td><td><input type="text" name="codigo"></td>
</tr>
<tr>
<td>Alterar Nome:</td> <td><input type="text" name="nome" size="50"></td>
</tr>
<tr>
<td>Alterar Endereco:</td> <td><input type="text" name="endereco" size="50"></td>
</tr>
<tr>
<td>Alterar Telefone:</td> <td><input type="text" name="telefone" size="11"></td>
</tr>
<tr>
<td>Alterar E-mail:</td> <td><input type="text" name="email" size="50"></td>
</tr>
</table>
<input type="submit" value="Gravar">
</form>
</body>
</html>

/* 12º Criar alterar.php e salavar em C:\wamp64\www\ProjetoPHP */

<?php
include 'conecta.php';
$codigo=$_REQUEST['codigo'];
$nome=$_REQUEST['nome'];
$endereco=$_REQUEST['endereco'];
$telefone=$_REQUEST['telefone'];
$email=$_REQUEST['email'];

$alterar="update clientes set codigo=$codigo,email='$email',endereco='$endereco',nome='$nome',telefone='$telefone'
where codigo=$codigo";
$resultado=mysqli_query($link, $alterar)or die("Erro no Alterar");

header('location: clientes.php');

?>
<div align="center">
<?php
include 'conecta.php';
$consulta="select * from clientes order by codigo";
$resultado=mysqli_query($link, $consulta) or die ("Erro de select");

echo "<table border=1>";
echo "<tr><td>CODIGO</td><td>NOME</td><td>ENDERECO</td><td>TELEFONE</td><td>EMAIL</td></tr>";
while($registro=mysqli_fetch_array($resultado))
{
echo "<tr><td>".$registro['codigo']."</td><td>".$registro['nome']."</td><td>".$registro['endereco']."</td><td>".$registro['telefone']."</td><td>"
.$registro['email']."</td><td><a href='alterar.html'>Alterar</a></td><td>
<a href='deletar.html'>Deletar</a></td></tr>";

}

mysqli_close($link);
?>
</div>


2 comentários:

  1. Your article is extraordinarily smart.I love to browse your diary's posts everyday and that i got vast facilitate from your blog and developed a replacement app music match app you'll check.Thanks for wonderful diary.

    ResponderExcluir
  2. Have you attempted this new app Avatar Life Mod Apk : that is certainly exceptional.

    ResponderExcluir