-
Notifications
You must be signed in to change notification settings - Fork 0
/
pagina_protegida.php
66 lines (55 loc) · 1.57 KB
/
pagina_protegida.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
<?php
session_start();
// Check if the user is authenticated
if (!isset($_SESSION['id_user'])) {
// If not authenticated, redirect to login page
header("Location: login.html");
exit();
}
$host = "localhost";
$dbname = "name-database";
$username = "useruname";
$password = "password";
$conn = new mysqli($host, $username, $password, $dbname);
if ($conn->connect_error) {
die("Error connecting to database, please try again" . $conn->connect_error);
}
$idUser = $_SESSION['id_user'];
// Customized query based on the same user id as the esp
$query = "SELECT * FROM table_name WHERE column_id_user = '$idUser'"; //access the information of that id
$result = $conn->query($query);
if ($result->num_rows > 0) {
// View user data
while ($row = $result->fetch_assoc()) {
$info1 = $row["info1"];
$info2 = $row["info2"];
// database data
}
} else {
}
$conn->close();
?>
<html>
<head>
<meta charset="utf-8">
<title>Previw Page </title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<!--update database -->
<form action="" method="POST">
<button input type="submit" name="update" value="update" ><img class="som">update database</button>
</form>
<h1 >info1:</h1>
<span><?= $info1 ?> </span>
<h2>info2:</h2>
<span><?= $info2 ?> </span>
<?php
if (isset($_POST['update'])) {
// Execute the php page that will update the database
include "update.php";
exit();
}
?>
</body>
</html>