Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Classe PHP
- class Usuario{
- private $nome;
- public function cadastrar($nome){
- $this->nome = $nome;
- $pdo = new PDO;
- $sql = "INSERT INTO usuarios" .$this->nome;
- $exec = $pdo->query($sql);
- if($sql->execute() == TRUE){
- return true;
- } else {
- return false;
- }
- }
- }
- // Script PHP
- if(isset($_POST["enviar"])){
- // Post formulário ...
- $nome = $_POST["nome"];
- if(isset($nome)){
- $user = new Usuario();
- if($user->cadastrar($nome) == TRUE){
- echo "Usuário cadastrado com sucesso";
- }
- }
- }
- // HTML
- <form action="">
- <input type="text" name="nome" />
- <input type="submit" name="enviar" value="Enviar" />
- </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement