-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsave.php
More file actions
executable file
·48 lines (31 loc) · 1.25 KB
/
Copy pathsave.php
File metadata and controls
executable file
·48 lines (31 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
include("db.class.php");
$empresa = utf8_decode($_POST['empresa']);
$id = utf8_decode($_POST['id']);
$mails = isset($_POST['mails'])? $_POST['mails'] : array();
try {
$sql = 'UPDATE empresa SET nombre=\''.$empresa.'\' WHERE id='.$id;
$sth = $conn->exec($sql);
$sql = 'DELETE FROM empresa_mail WHERE id_empresa='.$id;
$sth = $conn->exec($sql);
foreach ($mails as $mail) {
$sm = $conn->query("SELECT * from mail WHERE email='$mail'");
$result = $sm->fetchAll(PDO::FETCH_ASSOC);
if(count($result) == 1)
{
$sql = 'INSERT INTO empresa_mail (id_empresa,id_mail) VALUES ('.$id.','.$result[0]['id'].')';
$sth = $conn->exec($sql);
} else {
$sql = "INSERT INTO mail (email) VALUES ('$mail')";
$sth = $conn->exec($sql);
$idMail = $conn->lastInsertId();
$sql = "INSERT INTO empresa_mail (id_empresa,id_mail) VALUES ($id,$idMail)";
$sth = $conn->exec($sql);
}
}
echo "La empresa fue agregada al sistema exitosamente";
} catch(Exception $e) {
echo 'Error : '.$e->getMessage().'';
echo 'N� : '.$e->getCode();
}
?>