/
info.php
59 lines (51 loc) · 1.86 KB
/
info.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
<?php
require_once("functions.php");
$component_name="";
$component_name_error="";
$price="";
$price_error="";
if(isset($_POST["add_component"])){
if ( empty($_POST["component_name"])){
$component_name_error= "Palun sisesta komponendi nimi!";
}else{
$component_name = test_input($_POST["component_name"]);
}
if ( empty($_POST["price"]) ) {
$price_error = "Palun sisesta komponendi hind!";
}else{
$price = test_input($_POST["price"]);
}
if($component_name_error == "" && $price_error == ""){
$message = addComponent($component_name, $price);
if($message != ""){
$component_name = "";
$price = "";
}
}
}
function test_input($data) {
$data = trim($data); //võtab ära tühikud,enterid,tabid
$data = stripslashes($data); //võtab ära tagurpidi kaldkriipsud
$data = htmlspecialchars($data); //teeb htmli tekstiks, nt < läheb <
return $data;
}
?>
<html>
<head>
<meta charset="utf-8">
<title>Komponentide lisamine</title>
</head>
<body>
<p>Tere tulemast arvuti komponentide lehele!</p>
<p>Uute komponentide lisamiseks täida allolevad väljad.
Olemasolevate komponentide vaatamiseks vajuta <a href="http://localhost:5555/~earis/eksam/table.php">siia</a>. </p>
<h2>Lisa komponendid</h2>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post">
<label for ="component_name">Arvuti komponendi nimi</label><br>
<input id="component_name" name="component_name" placeholder="Komponent" type="text" value="<?php echo $component_name;?>" > <?=$component_name_error;?><br><br>
<label for ="price">Arvuti komponendi hind</label><br>
<input id="price" name="price" placeholder="Hind" type="text" value="<?php echo $price;?>"> <?=$price_error;?><br><br>
<input type="submit" name="add_component" value="Sisesta"><br>
</form>
</body>
</html>