Created
April 22, 2013 13:24
-
-
Save Bolinha1/5434853 to your computer and use it in GitHub Desktop.
Conexão com a base de dados.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
@header("Content-Type: text/html; charset=UTF-8",true) ; | |
mysql_connect('localhost', 'root', '') or die ("ERRO DE CONEXAO"); | |
mysql_select_db('bd_teste'); | |
mysql_query("SET NAMES 'utf8'"); | |
mysql_query('SET character_set_connection=utf8'); | |
mysql_query('SET character_set_client=utf8'); | |
mysql_query('SET character_set_results=utf8'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'conecta.php'; | |
function insere($campo1, $campo2, $campo3) | |
{ | |
$sql = mysql_query("INSERT INTO tb_teste (campo1, campo2, campo3) VALUES ($campo1, $campo2, $campo3)"); | |
if($sql) | |
echo 'Inseriu com sucesso'; | |
else | |
echo 'Falha ao inserir' .mysql_error(); | |
} | |
function listar($id) | |
{ | |
$sql = mysql_query("SELECT * FROM tb_teste WHERE id= $id"); | |
if($sql) | |
return $sql; | |
else | |
echo 'falha ao listar' .mysql_error(); | |
} | |
function remover($id) | |
{ | |
$sql = mysql_query("DELETE FROM tb_teste WHERE id= $id"); | |
if($sql) | |
echo 'Removeu com sucesso'; | |
else | |
echo 'Falha ao remover' .mysql_error(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Usando as funcoes | |
require 'funcoes.php'; | |
$id = $_POST['id']; | |
$campo1 = $_POST['campo_1']; | |
$campo2 = $_POST['campo_2']; | |
$campo3 = $_POST['campo_3']; | |
//Inserindo | |
insere($campo1, $campo2, $campo3); | |
//Listando | |
while($result = mysql_fetch_array(listar($id))) | |
{ | |
echo $result['id']. '<br />'; | |
echo $result['campo1']. '<br />'; | |
echo $result['campo2']. '<br />'; | |
echo $result['campo3']. '<br />'; | |
} | |
//remove | |
remove($id); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment