Created
February 22, 2014 23:17
-
-
Save davidchc/9163920 to your computer and use it in GitHub Desktop.
Exemplo : http://jsfiddle.net/729z9/
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 | |
if($_SERVER['REQUEST_METHOD'] == 'POST'){ | |
//Instancia a classe PDO | |
$pdo = new PDO("mysql:host=localhost;dbname=exemplo", "root", ""); | |
//Recupera o nome da empresa | |
$company = filter_input(INPUT_POST, 'company', FILTER_SANITIZE_ENCODED); | |
$stmt = $pdo->prepare("INSERT INTO company (nameCompany, createdCompany) VALUES (:name, NOW())"); | |
$stmt->bindValue(':name', $company); | |
$stmt->execute(); | |
//recuperar o ultimo ID | |
$idCompany = $pdo->lastInsertId(); | |
//recupera | |
$names = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_ENCODED); | |
$phones = filter_input(INPUT_POST, 'phone', FILTER_SANITIZE_ENCODED); | |
//Verificar se os valores o nome e telefone existe | |
if($names && $phones){ | |
//Percorre o array dos nomes | |
foreach($names as $i => $name){ | |
$stmt = $pdo->prepare("INSERT INTO employee (nameEmployee, phoneEmployee) VALUES (:name,:phone)"); | |
$stmt->bindValue(':name', $name); | |
$stmt->bindValue(':phone', $phones[$i]); | |
$stmt->execute(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment