-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateProduct.php
36 lines (30 loc) · 994 Bytes
/
createProduct.php
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
<?php
include 'header.php';
echo '<div id="conteudo">
<div class="texto">';
if ($_SESSION['permission'] == "reader")
{
echo ' Precisa de ter permissões de writer para criar documentos!';
exit();
}
$db = new PDO('sqlite:database/documents.db');
$query = $db->prepare("SELECT * FROM Product WHERE ProductCode = ?");
$query->execute(array($_POST['ProductCode']));
$product = $query->fetch();
if (!$product)
{
$Insert= $db->prepare("INSERT INTO Product(ProductCode,ProductDescription, UnitPrice, UnitOfMeasure) VALUES (:code, :description, :price, :measure)");
$Insert->bindParam(':code',$_POST['ProductCode'],PDO::PARAM_INT);
$Insert->bindParam(':description',$_POST['ProductDescription'],PDO::PARAM_STR);
$Insert->bindParam(':price',$_POST['UnitPrice'],PDO::PARAM_INT);
$Insert->bindParam(':measure' ,$_POST['UnitOfMeasure'],PDO::PARAM_STR);
$Insert->execute();
echo 'Produto adicionado!';
}
else
{
echo 'Produto já existente!';
}
?>
</div>
</div>