forked from earist/3.kodutoo-III-ruhm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_data.php
101 lines (75 loc) · 2.64 KB
/
db_data.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
<?php
if(isset($msqly)){
die('Püüad mind häkkida');
}
if(!isset($_SESSION["id"])){
header("id");
}
if(isset($_GET["logout"])){
//aadressireal on olemas muutuja logout
//kustutame kõik session muutujad ja peatame sessiooni
session_destroy();
header("Location: login.php");
}
?>
<p>
<a href="?logout=1"> Logi välja <a>
</p>
<?php
$errors = array();
$input = array();
$show_form = False ;
$time=date("Y-m-d");
if($_SERVER["REQUEST_METHOD"] == "POST") {
//defineerime array ja käime kogu tsükli läbi muutujan fild for loop.
foreach(array('name','voit', 'kaotus','vslamm','ssamm','ristit') as $field){
if ( empty($_POST['name'])) {
$errors[$field] = "See väli on kohustuslik";
}else{
$input[$field] = cleanInput($_POST[$field]);
}
}
if(empty($errors)){
//Salvestame AB'i
$stmt = $mysqli->prepare("INSERT INTO users2 (name, voit, kaotus, vslamm, ssamm, ristit, time) VALUES (?,?,?,?,?,?,?)");
if(!$stmt){
die("juhtus viga".$mysqli->error);
}
$stmt->bind_param("sssssss", $input['name'], $input['voit'], $input['kaotus'], $input['vslamm'], $input['ssamm'], $input['ristit'],$time);
echo $time;
$stmt->execute();
$stmt->close();
$_SESSION['lisa']=True;
$show_form = True ;
}
}
?>
<html>
<head>
<meta charset="UTF-8">
<title>Mängude andmebaas</title>
</head>
<body>
<?php if($show_form){
echo '<span style="color:green"> Andmed on edastatud edukalt </span> ';
}
?>
<h2> Lisa mängitud mängu andmed andmebaasi</h2>
<form action="index.php?action=registreeri" method="post" >
<input name="name" type="name" placeholder="Mängija nimi" value="<?php if(isset($input['name'])){echo $input['name'];} ?>">
<span style="color:red" ><?php if(isset($errors['name'])){echo $errors['name'];} ?> </span><br><br>
<input name="voit" type="number" placeholder="Võit" value="<?php if(isset($input['voit'])){echo $input['voit'];} ?>">
<br><br>
<input name="kaotus" type="number" placeholder="Kaotus"value="<?php if(isset($input['kaotus'])){echo $input['kaotus'];} ?>">
<br><br>
<input name="vslamm" type="number" placeholder="Väike slämm" value="<?php if(isset($input['vslamm'])){echo $input['vslamm'];} ?>">
<br><br>
<input name="ssamm" type="number" placeholder="Suur slämm" value="<?php if(isset($input['ssamm'])){echo $input['ssamm'];} ?>">
<br><br>
<input name="ristit" type="number" placeholder="Kaks ristit" value="<?php if(isset($input['ristit'])){echo $input['ristit'];} ?>">
<br><br>
<input type="submit" name="create" value="Lae Andmed">
<a href="redigeeri.php">Siin saad redigeerida</a>
</form>
<body>
<html>