Last active
October 4, 2018 20:40
-
-
Save jhowbhz/325f31bc5a031490b695b13c8a1907a9 to your computer and use it in GitHub Desktop.
exemplo de insert mysqli
This file contains hidden or 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 | |
// CONECTE-SE AO DB | |
$servername = "localhost"; | |
$username = "username"; | |
$password = "password"; | |
$dbname = "myDB"; | |
// RECEBA O POST | |
$campo_1 = $_POST['campo1']; | |
$campo_2 = $_POST['campo2']; | |
$campo_3 = $_POST['campo3']; | |
// CRIE UMA CONEXÃO | |
$conn = new mysqli($servername, $username, $password, $dbname); | |
// VERIFIQUE A CONEXÃO | |
if ($conn->connect_error) { | |
die("Connection failed: " . $conn->connect_error); | |
} | |
// INSIRA OS VALORES | |
$sql = "INSERT INTO tabela_db (campo1, campo2, campo3) | |
VALUES ('$campo_1', '$campo_2', '$campo_3')"; | |
if ($conn->query($sql) === TRUE) { | |
echo "DADOS INCLUIDOS"; | |
}else | |
echo "ERRO ENCONTRADO: " . $sql . "<br>" . $conn->error; | |
} | |
$conn->close(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment