www/includes/db_inventory_suppliers.php

Sat, 11 Aug 2018 22:49:44 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 11 Aug 2018 22:49:44 +0200
changeset 10
606b4af8f918
child 18
395833e20f88
permissions
-rw-r--r--

Start of the merge with another unfinished project

10
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 <?php
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 require($_SERVER['DOCUMENT_ROOT']."/config.php");
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 require($_SERVER['DOCUMENT_ROOT']."/version.php");
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 #Connect to the database
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 $connect = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME);
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 if (! $connect) {
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 }
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 // get data and store in a json array
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 $query = "SELECT * FROM inventory_suppliers";
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 if (isset($_GET['insert'])) {
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 // INSERT COMMAND
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 $sql = "INSERT INTO `inventory_suppliers` SET name='" . mysqli_real_escape_string($connect, $_GET['name']);
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 $sql .= "', address='" . mysqli_real_escape_string($connect, $_GET['address']);
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 $sql .= "', city='" . mysqli_real_escape_string($connect, $_GET['city']);
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 $sql .= "', zip='" . mysqli_real_escape_string($connect, $_GET['zip']);
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20 $sql .= "', country='" . mysqli_real_escape_string($connect, $_GET['country']);
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21 $sql .= "', website='" . mysqli_real_escape_string($connect, $_GET['website']);
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22 $sql .= "', email='" . mysqli_real_escape_string($connect, $_GET['email']);
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23 $sql .= "', phone='" . mysqli_real_escape_string($connect, $_GET['phone']);
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24 $sql .= "', notes='" . mysqli_real_escape_string($connect, $_GET['notes']);
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25 $sql .= "';";
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26 error_log("\"$sql\"");
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 $result = mysqli_query($connect, $sql) or die("SQL Error 1: " . mysqli_error($connect));
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28 error_log("result " . $result);
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29 echo $result;
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
31 } else if (isset($_GET['update'])) {
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
32 // UPDATE COMMAND
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33 $sql = "UPDATE `inventory_suppliers` SET name='" . mysqli_real_escape_string($connect, $_GET['name']);
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34 $sql .= "', address='" . mysqli_real_escape_string($connect, $_GET['address']);
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35 $sql .= "', city='" . mysqli_real_escape_string($connect, $_GET['city']);
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36 $sql .= "', zip='" . mysqli_real_escape_string($connect, $_GET['zip']);
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37 $sql .= "', country='" . mysqli_real_escape_string($connect, $_GET['country']);
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38 $sql .= "', website='" . mysqli_real_escape_string($connect, $_GET['website']);
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39 $sql .= "', email='" . mysqli_real_escape_string($connect, $_GET['email']);
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40 $sql .= "', phone='" . mysqli_real_escape_string($connect, $_GET['phone']);
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41 $sql .= "', notes='" . mysqli_real_escape_string($connect, $_GET['notes']);
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42 $sql .= "' WHERE record='" . $_GET['record'] . "';";
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43 error_log("\"$sql\"");
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44 $result = mysqli_query($connect, $sql) or die("SQL Error 1: " . mysqli_error($connect));
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45 error_log("result " . $result);
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46 echo $result;
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
47
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48 } else if (isset($_GET['delete'])) {
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49 // DELETE COMMAND
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50 // FIXME: need to check if the record is in use
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51 $sql = "DELETE FROM `inventory_suppliers` WHERE record='".$_GET['record']."';";
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52 error_log("\"$sql\"");
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
53 $result = mysqli_query($connect, $sql) or die("SQL Error 1: " . mysqli_error($connect));
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54 error_log("result " . $result);
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
55 echo $result;
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
56
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
57 } else {
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
58 // SELECT COMMAND
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
59 $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect));
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61 $suppliers[] = array(
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
62 'record' => $row['record'],
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
63 'name' => $row['name'],
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
64 'address' => $row['address'],
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
65 'city' => $row['city'],
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
66 'zip' => $row['zip'],
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
67 'country' => $row['country'],
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68 'website' => $row['website'],
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69 'email' => $row['email'],
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
70 'phone' => $row['phone'],
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
71 'notes' => $row['notes']
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72 );
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73 }
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
74 echo json_encode($suppliers);
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75 }
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
76 ?>

mercurial