Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Login on db #1

Open
wants to merge 15 commits into
base: budowanieDB
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"pasteAndIndent.selectAfter": true
}
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
php_HelloWorld

TODO:

-oddzielic tytuł main-contentu (divy -> grid display -> gap)
30 changes: 30 additions & 0 deletions add-ah30.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
session_start();

if(!isset($_POST['place']))
{
header('Location: inventory-panel.php');
exit();
}

if(!preg_match('/\A\[[0-9A-Za-z]{2}\.[0-9A-Za-z]{2}\.[0-9A-Za-z]{2}\]$/', $_POST['address'], $matches)){
$_SESSION['invalid-address'] = true;
header("Location: {$_POST['place']}");
exit();
}

$db = require_once 'database.php';

$query = $db->prepare('SELECT * FROM ah30 WHERE address = ?');
$query->execute([$_POST['address']]);

$e100 = $query->fetchColumn();
if(!$e100){
$query = $db->prepare('INSERT INTO ah30 (address, available) VALUES (?,?)');
$query->execute([$_POST['address'], TRUE]);
}
else{
$_SESSION['existing-address'] = true;
}
header("Location: {$_POST['place']}");
?>
25 changes: 25 additions & 0 deletions add-current-element.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
session_start();

if(!isset($_POST['place']))
{
header('Location: inventory-panel.php');
exit();
}

$db = require_once 'database.php';

$invPartsQuery = $db->prepare("SELECT quantity FROM inventory WHERE name=? ");
$invPartsQuery->execute([$_POST['name-curr']]);

$partQty = $invPartsQuery->fetch();

$partQty = $partQty['quantity'];

$partQty += intval($_POST['quantity-curr']);

$query = $db->prepare('UPDATE `inventory` SET `quantity` = :quantity WHERE `inventory`.`name` = :namee');
$query->execute([':namee' => $_POST['name-curr'], ':quantity' => intval($partQty)]);

header("Location: {$_POST['place']}");
?>
30 changes: 30 additions & 0 deletions add-e100.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
session_start();

if(!isset($_POST['place']))
{
header('Location: inventory-panel.php');
exit();
}

if(!preg_match('/\A\[[0-9A-Za-z]{2}\.[0-9A-Za-z]{2}\.[0-9A-Za-z]{2}\]$/', $_POST['address'], $matches)){
$_SESSION['invalid-address'] = true;
header("Location: {$_POST['place']}");
exit();
}

$db = require_once 'database.php';

$query = $db->prepare('SELECT * FROM e100 WHERE address = ?');
$query->execute([$_POST['address']]);

$e100 = $query->fetchColumn();
if(!$e100){
$query = $db->prepare('INSERT INTO e100 (address, available) VALUES (?,?)');
$query->execute([$_POST['address'], TRUE]);
}
else{
$_SESSION['existing-address'] = true;
}
header("Location: {$_POST['place']}");
?>
16 changes: 8 additions & 8 deletions add-new-element.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@ function clog( $data ){
echo '</script>';
}

session_start(); #otwiera sesje (zmienne)
session_start();

//formulaz wysłany?
if(!isset($_POST['place']))
{
header('Location: inventory-panel.php');
exit();
}

if(strlen($_POST['name'])<3){
//warunek ilosci znakow
if(strlen($_POST['name-new'])<3){
$_SESSION['name_len'] = true;
header("Location: {$_POST['place']}");
exit();
}

require_once 'database.php';
$db = require_once 'database.php';

$query = $db->prepare('INSERT INTO inventory (nazwa, ilosc, symbol) VALUES (:namee, :quantity, :symbol)');
$query->bindValue(':namee', $_POST['name'], PDO::PARAM_STR);
$query->bindValue(':quantity', intval($_POST['quantity']), PDO::PARAM_INT);
$query->bindValue(':symbol', $_POST['symbol'], PDO::PARAM_STR);
$query = $db->prepare('INSERT INTO inventory (name, quantity, symbol) VALUES (:namee, :quantity, :symbol)');
$query->bindValue(':namee', $_POST['name-new'], PDO::PARAM_STR);
$query->bindValue(':quantity', intval($_POST['quantity-new']), PDO::PARAM_INT);
$query->bindValue(':symbol', $_POST['symbol-new'], PDO::PARAM_STR);
$query->execute();


Expand Down
34 changes: 34 additions & 0 deletions add-pinio.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
session_start();

if(!isset($_POST['place']))
{
header('Location: inventory-panel.php');
exit();
}

$db = require_once 'database.php';

$query = $db->prepare('SELECT * FROM ah30 WHERE address = ?');
$query->execute([$_POST['address']]);

$ah30 = $query->fetchAll();
if($ah30){

if($ah30[0]['available']){
$query = $db->prepare('INSERT INTO pinio (address, available) VALUES (?,?)');
$query->execute([$_POST['address'], TRUE]);

$query = $db->prepare('UPDATE ah30 SET available = ? WHERE ah30.address = ?');
$query->execute([FALSE, $_POST['address']]);
}
else{
$_SESSION['no-available'] = true;
}

}
else{
$_SESSION['nonexisting-address'] = true;
}
header("Location: {$_POST['place']}");
?>
26 changes: 26 additions & 0 deletions add-set.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
session_start();

if(!isset($_POST['place']))
{
header('Location: inventory-panel.php');
exit();
}
$mask_pad = FALSE;
if(isset($_POST['pad'])) $mask_pad = TRUE;

$db = require_once 'database.php';

$query = $db->prepare('INSERT INTO `sets` (e100, pinio, mask_in, mask_out, trzpien, pad) VALUES (:e100, :pinio, :mask_in, :mask_out, :trzpien, :pad)');
$query->execute(
[
e100 => $_POST['e100-address'],
pinio => $_POST['pinio-address'],
mask_in => $_POST['mask-in'],
mask_out => $_POST['mask-out'],
trzpien => $_POST['trzpien'],
pad => $mask_pad
]);

header("Location: {$_POST['place']}");
?>
16 changes: 16 additions & 0 deletions change-ah30.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
session_start();

if(!isset($_POST['place']))
{
header('Location: inventory-panel.php');
exit();
}

$db = require_once 'database.php';

$query = $db->prepare('UPDATE ah30 SET available = ? WHERE ah30.address = ?');
$query->execute([$_POST['availibility'], $_POST['address-curr']]);

header("Location: {$_POST['place']}");
?>
16 changes: 16 additions & 0 deletions change-e100.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
session_start();

if(!isset($_POST['place']))
{
header('Location: inventory-panel.php');
exit();
}

$db = require_once 'database.php';

$query = $db->prepare('UPDATE e100 SET available = ? WHERE e100.address = ?');
$query->execute([$_POST['availibility'], $_POST['address-curr']]);

header("Location: {$_POST['place']}");
?>
Loading