-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit_vendor.php
104 lines (100 loc) · 3.03 KB
/
edit_vendor.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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/style.css">
<title>Baza danych dostawców</title>
</head>
<?php
session_start(); //starts the session
if($_SESSION['imie']){ //checks if user is logged in
}
else{
header("location:index.php"); // redirects if user is not logged in
}
$user = $_SESSION['imie']; //assigns user value
$id_exists = false;
?>
<body>
<div id="wrapper">
<h3>Edytuj dostawce</h3>
<div id="header" style="text-align:right">
<p>Witam, <?php Print "$user"?>!</p> <!--Displays user's name-->
<a href="logout.php">Wylogować się</a><br/>
<a href="home.php">Powrot do początkowej</a>
</div>
<h4>Obecnie wybrany:</h4>
<table border="1px" width="100%">
<tr>
<th>Id</th>
<th>Nazwa</th>
<th>Kontakt</th>
<th>Kraj</th>
</tr>
<?php
if(!empty($_GET['id']))
{
$id = $_GET['id'];
$_SESSION['id'] = $id;
$id_exists = true;
include "db_connect.php";
$query = mysql_query("SELECT * FROM dostawca WHERE id='$id'"); // SQL Query
$count = mysql_num_rows($query);
if($count > 0)
{
while($row = mysql_fetch_array($query))
{
Print "<tr>";
Print '<td align="center">'. $row['id'] . "</td>";
Print '<td align="center">'. $row['nazwa'] . "</td>";
Print '<td align="center">'. $row['kontakt']. "</td>";
Print '<td align="center">'. $row['kraj']. "</td>";
Print "</tr>";
$row_values=[$row['nazwa'], $row['kontakt'], $row['kraj']];
}
}
else
{
$id_exists = false;
}
}
?>
</table>
<br/>
<div id="edit">
<?php
if($id_exists)
{
?>
<form action="edit_vendor.php" style="width:30%" method="POST">
<span>Wprowadż nową nazwę:</span> <input type="text" id="edit_text" name="nazwa" value="<?php echo ($row_values[0]); ?>" style='width:100%'/><br/>
<span>Wprowadż nowy kontakt: </span> <input type="text" name="kontakt" value="<?php echo ($row_values[1]); ?>" style='width:100%'/><br/>
<span>Wprowadż nowy kraj:</span> <input type="text" name="kraj" value="<?php echo ($row_values[2]); ?>" style='width:100%'/><br/>
<input type="submit" value="Aktualizuj dostawcę"/>
</form>
<?php
}
else
{
Print '<h2 align="center">Niema danych do edytowania.</h2>';
}
?>
</div>
<div id="footer">
<p><a href="https://sites.google.com/site/infoteczka/" >(c) ŻAK. Wrocław, 2017 </a></p>
</div>
</div>
</body>
</html>
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
include "db_connect.php";
$id = $_SESSION['id'];
$name = mysql_real_escape_string($_POST['nazwa']);
$contact = mysql_real_escape_string($_POST['kontakt']);
$state = mysql_real_escape_string($_POST['kraj']);
mysql_query("UPDATE dostawca SET nazwa='$name', kontakt='$contact', kraj='$state' WHERE id='$id'") ;
header("location: home.php");
}
?>