Agendinha PHP+MySOL
Publicado por Lisandro Guerra 07/07/2009
[ Hits: 15.030 ]
Homepage: https://spartanix.com/
Um exemplo de agenda de contatos bem simples usando PHP e MySQL. Registra nome , telefone e celular e ordena a lista por nome.
No arquivo ZIP pra download tem o arquivo agenda.php, um arquivo agenda.sql pra importar no MySQL e a figura pix.gif pra organizar a tabela html.
<?
// Requisições apenas do localhost
extract($_POST);
extract($_SERVER);
$host = "127.0.0.1";
$timeout = "1";
if ($REMOTE_ADDR) {
if ($REMOTE_ADDR != $host) {
echo "<p><h2> Desconectado do cliente $REMOTE_ADDR <h2></p>";
exit;
}
}
?>
<html>
<head>
<title>Agenda de Contatos</title>
</head>
<body>
<p>
<h1>Agenda de Contatos</h1>
<?
if(!mysql_connect("localhost","root",""))
{
echo "<h2>Erro de Conexão</h2>";
die();
}
mysql_select_db("agenda");
?>
<form action=agenda.php method=get>
<table border=0 cellpadding=0 cellspacing=0>
<tr><td>Nome:</td><td><input type=text size=30 name=Nome></td></tr>
<tr><td>Telefone:</td><td><input type=text size=10 name=Telefone></td></tr>
<tr><td>Celular:</td><td> <input type=text size=10 name=Celular></td></tr>
<tr><td></td><td><input type=submit border=0 value="Gravar"></td></tr>
</table>
</form>
<p>
<table border=0 cellpadding=0 cellspacing=0>
<tr bgcolor=#888888>
<td><img src=img/pix.gif width=15 height=30></td>
<td><img src=img/pix.gif width=220 height=5><br><b>Nome</b></td>
<td><img src=img/pix.gif width=120 height=5><br><b>Telefone</b></td>
<td><img src=img/pix.gif width=120 height=5><br><b>Celular</b></td>
<td><img src=img/pix.gif width=120 height=5><br><b>Apagar</b></td>
<td><img src=img/pix.gif width=15 height=30></td>
</tr>
<?
if($_REQUEST['Nome']!="")
{
if($Telefone=="")$Telefone="NULL";
$Nome=htmlentities($_REQUEST['Nome']);
$Telefone=htmlentities($_REQUEST['Telefone']);
$Celular=htmlentities($_REQUEST['Celular']);
mysql_query("INSERT INTO ag (Nome,Telefone,Celular) VALUES('$Nome','$Telefone','$Celular');");
}
if($_REQUEST['action']=="del")
{
mysql_query("DELETE FROM ag WHERE id={$_REQUEST['id']};");
}
$result=mysql_query("SELECT id,Nome,Telefone,Celular FROM ag ORDER BY Nome;");
$i=0;
while( $row=mysql_fetch_array($result) )
{
if($i>0)
{
echo "<tr valign=bottom>";
echo "<td bgcolor=#ffffff colspan=5></td>";
echo "</tr>";
}
echo "<tr valign=center>";
echo "<td><img src=img/pix.gif width=15 height=30></td>";
echo "<td><b>".$row['Nome']."</b></td>";
echo "<td>".$row['Telefone']." </td>";
echo "<td>".$row['Celular']." </td>";
echo "<td><a onclick=\"return confirm('Tem Certeza?');\" href=agenda.php?action=del&id=".$row['id']."><span>[Apagar]</span></a></td>";
echo "<td></td>";
echo "</tr>";
$i++;
}
?>
</table>
</body>
</html>
PHP5 gravando, recuperando e deletando imagens no banco de dados MYSQL
Função para somar datas usando MySQL e PHP
Script Para Conectar-se Ao Banco de dados PostGreSQL [golfinho/Elefante]
Testando servidor MySQL e base de dados
Classe PHP para acesso a bancos de dados em MySQL
Cirurgia para acelerar o openSUSE em HD externo via USB
Void Server como Domain Control
Modo Simples de Baixar e Usar o bash-completion
Monitorando o Preço do Bitcoin ou sua Cripto Favorita em Tempo Real com um Widget Flutuante
Atualizar Linux Mint 22.2 para 22.3 beta
Jogar games da Battle.net no Linux com Faugus Launcher
Como fazer a Instalação de aplicativos para acesso remoto ao Linux
Conky, alerta de temperatura alta (10)
Assisti Avatar 3: Fogo e Cinzas (3)
Duas Pasta Pessoal Aparecendo no Ubuntu 24.04.3 LTS (42)









