-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmysqltest.php
More file actions
159 lines (140 loc) · 4.2 KB
/
mysqltest.php
File metadata and controls
159 lines (140 loc) · 4.2 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
ob_start();
session_start();
//require_once 'dbconnect.php';
// if session is not set this will redirect to login page
if(!isset($_SESSION['user'])) {
header("Location: login.php");
exit;
}
function sessionTimeOut(){
$logLength = 900;
$ctime = strtotime("now");
if(!isset($_SESSION['sessionX'])){
$_SESSION['sessionX'] = $ctime;
}else{
if((strtotime("now") - $_SESSION['sessionX']) > $logLength){
session_destroy();
header("Location: login.php");
exit;
}else{
$_SESSION['sessionX'] = $ctime;
}
}
}
?>
<html>
<head>
<title>Balance</title>
<link rel="stylesheet" type="text/css" href="inventory.css">
<?php sessionTimeOut();
$session = $_SESSION['user'];
echo "Bine ai venit " .$session;
?>
</head>
<body>
<h2>Label Team Inventory System</h2>
<ul>
<li><a class="active" href="mysqltest.php">Balance</a></li>
<li><a href="addrmv.php">Add</a></li>
<li><a href="update.php">Update</a></li>
<li><a href="index.php">Balance by Loc</a></li>
<li><a href="delete.php">Delete</a></li>
<li><a href="export.html">Export</a></li>
<li><a href="transactions.php">Transactions</a></li>
<li><a href="logout.php?logout">Logout</a></li>
</ul>
<form id="balance" method="POST" action="<?php echo $_SERVER['PHP_SELF']?>" name="balance">
<select id="select" name="option">
<option value="monitor" name="monitor">Monitor</option>
<option value="imprimanta" name="imprimanta">Imprimanta</option>
<option value="ups" name="ups">UPS</option>
<option value="scaner" name="scaner">Scaner</option>
<option value="pc" name="pc">PC</option>
<option value="compimp" name="compimp">Componente Imprimanta</option>
<option value="comppc" name="comppc">Componente PC</option>
<option value="amg_assets" name="amg_assets">AMG Assets</option>
<option value="turn_aps" name="turn_aps">Turn APS</option>
</select><br>
<input id="sub1" type="submit" name="submit" value="Submit" /><br>
<table class="t1">
<tr id="tr">
<thead>
<th id="th1">Serial Number</th>
<th id="th2">Descriere</th>
<th id="th3">Locatie</th>
<th id="th9">AMG</th>
<th id="th4">Status</th>
<th id="th5">Capex</th>
<th id="th6">Numar Inventar FAR</th>
<th id="th7">Observatii</th>
<th id="th8">Pret</th>
</thead>
</tr>
<?php
$servername = "localhost";
$dbname = "mydb";
if($session === "Raul Filimon" or $session === "Casian Buta"){
$username = "root";
$password = "Multiread23";
}else{
$username = "generic_user";
$password = "AYVkq4^Sb=YFBvu+";
}
//Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
//check connection
if($conn->connect_error){
die("Connection Error: " . $conn->connect_error);
}
//echo "Connected succesfully<br>";
/*Create Database
$sql = "CREATE DATABASE myDB";
if($conn->query($sql) === TRUE){
echo "Database created successfully";
} else {
echo "<br>Error creating database: " .$conn->error;
}*/
/*sql to create table
$sql = "CREATE TABLE MyGuests (
id INT(6) PRIMARY KEY AUTO_INCREMENT,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP
)";*/
//insert into tables example
/*$sql = "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('John', 'Doe', 'john@example.com')";
if($conn->query($sql) === TRUE){
echo "Succesfully inserted into table<br>";
} else {
echo "Error inserting into table:<br> " .$conn->error;
}*/
if(isset($_POST['submit'])){
$sql = "SELECT SerialNumber, Descriere, Location, AMG, Status, Capex, nr_inv_far, observatii, Pret FROM ".$_POST['option']."";
$result = $conn->query($sql);
if($result->num_rows > 0){
//output data for each row
while($row = $result->fetch_assoc()){
echo "<tr><tbody>
<td>" . $row["SerialNumber"]."</td>".
"<td>" . $row["Descriere"]. "</td>".
"<td>" . $row["Location"]. "</td>".
"<td>" . $row["AMG"] . "</td>".
"<td>" . $row["Status"]. "</td>".
"<td>" . $row["Capex"]. "</td>".
"<td>" . $row["nr_inv_far"]. "</td>".
"<td>" . $row["observatii"]. "</td>".
"<td>" . $row["Pret"]. "</td></tbody></tr>";
}
}else {
echo "0 results";
}
}
$conn->close();
?>
</div>
</body>
</html>
<?php ob_end_flush(); ?>