Skip to content

Instantly share code, notes, and snippets.

@davidchc davidchc/salvar.php
Created Feb 22, 2014

Embed
What would you like to do?
<?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
You can’t perform that action at this time.