-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddAc.php
More file actions
112 lines (98 loc) · 3.76 KB
/
Copy pathaddAc.php
File metadata and controls
112 lines (98 loc) · 3.76 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
<!--This is data to start the server, is the Model!-->
<?php
require_once "pdo.php";
session_start();
//add new data user.
if(isset($_POST["name"]) && isset($_POST["lastName"])
&& isset($_POST["email"]) && isset($_POST["bornAge"])){
$sqlInsert = "INSERT INTO users (name, lastName, email, bornAge)
VALUES (:name, :lastName, :email, :bornAge)";
$stmt = $pdo->prepare($sqlInsert);
$stmt->execute(array(
":name"=>$_POST["name"],
":lastName"=>$_POST["lastName"],
":email"=>$_POST["email"],
":bornAge"=>$_POST["bornAge"],
));
//POST-redirect-GET
header("location: addAC.php");
return;
}
function showData(){ //Why this do not work? I do not know. It is the same.
$stmt2 = $pdo->query("SELECT * FROM users");
while($row = $stmt2->fetch(PDO::FETCH_ASSOC)){
echo("<tr><td>");
echo($row["id"]);
echo("</td><td>");
echo($row["name"]);
echo("</td><td>");
echo($row["lastName"]);
echo("</td><td>");
echo($row["email"]);
echo("</td><td>");
echo($row["bornAge"]);
echo("</td></tr>");
}
}
?>
<!--This is the View, and how it will be show to the user-->
<html>
<head>
<meta charset="uft-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="./styles.css" media="screen" rel="stylesheet" type="text/css">
<title>Adding Users</title>
</head>
<body>
<header>
<h1>Add new accounts</h1>
</header>
<main>
<div class="tableData">
<!--This is for show the data-->
<p>Stored data in database:</p>
<table>
<tr>
<td>ID</td>
<td>Name</td>
<td>Last Name</td>
<td>E-mail</td>
<td>Born</td>
</tr>
<?php
//showData();
$stmt2 = $pdo->query("SELECT * FROM users");
while($row = $stmt2->fetch(PDO::FETCH_ASSOC)){
echo("<tr><td>");
echo($row["id"]);
echo("</td><td>");
echo($row["name"]);
echo("</td><td>");
echo($row["lastName"]);
echo("</td><td>");
echo($row["email"]);
echo("</td><td>");
echo($row["bornAge"]);
echo("</td></tr>");
}
?>
</table>
</div>
<div class="form">
<form method="post">
<p>Name: <br><input type="text" name="name" size="40"></p>
<p>Last Name: <br><input type="text" name="lastName" size="40"></p>
<p>E-mail: <br><input type="text" name="email" size="40"></p>
<p>Born age: <br><input type="text" name="bornAge" size="4"></p>
<p><input type="submit" value="Add New"></p>
</from>
</div>
<h4><a class="button" href="./deleteAc.php">Delete users?</a></h4>
<h4><a class="button" href="./index.php">Home</a></h4>
</main>
<footer>
<p>Dynamic web page developed by: Michael Rodriguez Gamboa. <br>
All mistakes and rights reserved. Costa Rica. 2020. <p>
</footer>
</body>
</html>