-
Notifications
You must be signed in to change notification settings - Fork 1
/
edit.php
105 lines (86 loc) · 3.15 KB
/
edit.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
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>The Game of Shares</title>
<link href='css/materialize.min.css' rel='stylesheet' type='text/css' media='screen, projection'>
<link href="css/custom.css" rel="stylesheet" type="text/css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<?php
include "conn.inc.php";
?>
<div class="navbar-fixed">
<nav id="nav">
<div class="nav-wrapper">
<a href="index.php" id="logo" class="brand-logo">The Game Of Shares</a>
<ul id="nav-mobile" class="right">
<?php
if(isset($_SESSION['admin_name']) && !empty($_SESSION['admin_name']))
{
echo "<li><a href='newcompany.php'> Add a new company</a></li>";
echo "<li><a href='edit.php?changeprice='>Change the stock prices</a></li>";
echo "<li><a href='logout.php'>Logout</a></li>";
}
else
echo "<li><a href='login.php'>User Login</a></li>";
?>
</ul>
</div>
</nav>
</div>
<div class="container">
<?php
if(!isset($_SESSION['admin_name']) || empty($_SESSION['admin_name']))
{
header("Location:index.php");
}
//form for changing the stock prices for all the companies
if(isset($_GET['changeprice']))
{
$query_get_company_id = "SELECT * FROM companies";
if($run_get_company_id = mysqli_query($conn, $query_get_company_id))
{
if(mysqli_num_rows($run_get_company_id) >= 1)
{
echo "<br><br><h5>Change the stock prices of any company:</h5><br><br>";
while($array = mysqli_fetch_assoc($run_get_company_id))
{
$company_id_edit_price = $array['id'];
$company_name = $array['name'];
$company_abbr = $array['abbrivation'];
$company_description = $array['description'];
$company_no_shares = $array['total_shares'];
$company_stock_price = $array['stock_price'];
echo "<br> <br><form action='edit.php' class='col s12' method='get' >
$company_name($company_abbr):
<div class='row'>
<input type='number' value='$company_stock_price' class='col s8' name='new_stock_price'>
<input type='number' value='$company_id_edit_price' name='id' hidden>
<input type='submit' class='btn' value='Change Price' class='col s4'>
</div>
</form> ";
}
}
}
}
//change the values of the stock in the database
//ie insert into stock_prices table
if(isset($_GET['new_stock_price']) && isset($_GET['id']) && !empty($_GET['new_stock_price']) && !empty($_GET['id']))
{
$new_stock_price = $_GET['new_stock_price'];
$company_id_new_price = $_GET['id'];
$query_change_price = "INSERT INTO stock_prices(company_id, stock_price) VALUES('$company_id_new_price','$new_stock_price');";
if(mysqli_query($conn, $query_change_price))
{
mysqli_query($conn, "UPDATE `companies` SET `stock_price` = '$new_stock_price' WHERE `id` = $company_id_new_price");
header("Location:admin.php");
}
}
?>
<script type="text/javascript" src="js/jquery-3.1.0.min.js"></script>
<script type="text/javascript" src="js/materialize.js"></script>
</div>
</body>
</html>