-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathveebirakendusedupload_photo.php
83 lines (62 loc) · 2.28 KB
/
veebirakendusedupload_photo.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
<?php
require_once "../../../conf.php";
$news_input_error = null;
/* var_dump($_POST); Massiivi nimi, On olemas ka $_GET */
if(isset($_POST["news_submit"] )){
if(empty($_POST["news_title_input"])){
$news_input_error = "Uudise Pealkiri on puudu! ";
}
if(empty($_POST["news_content_input"])){
$news_input_error .= "Uudise tekst on puudu!"; /* .= Võta senine väärtus juurde*/
}
if(empty($_POST["news_input_error"])){
store_news($_POST["news_title_input"], $_POST["news_content_input"], $_POST["news_author_input"]);
}
}
function store_news($news_title, $news_content, $news_author){
/* echo $news_title .$news_content .$news_author; */
/*echo $GLOBALS["server_host"]; */
/* loome andmebaasi serveriga ja baasiga ühenduse*/
$conn = new mysqli($GLOBALS["server_host"], $GLOBALS["server_user_name"], $GLOBALS["server_password"], $GLOBALS["database"]);
/* Määrame suhtluseks kodeeringu*/
$conn -> set_charset("utf8");
/* Valmistan ette SQL käsu*/
$stmt = $conn -> prepare("INSERT INTO vr21_news (vr21_news_news_title, vr21_news_news_content, vr21_news_news_author) VALUES(?,?,?) ");
echo $conn -> error;
/* i - integer s - string d - decimal PS! paramiga JÄRJEKORD!!!!!*/
$stmt -> bind_param("sss", $news_title, $news_content, $news_author);
$stmt -> execute();
$stmt -> close();
$conn -> close();
}
?>
<!DOCTYPE html>
<html lang="et">
<head>
<meta charset="utf-8">
<title>Veebirakendused ja nende loomine 2021</title>
</head>
<body>
<h1>
Uudiste lisamine
</h1>
<p>See leht on valminud õppetöö raames!</p>
<hr>
<form method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<label for="news_title_input">Uudise pealkiri</label>
<br>
<input type="text" id="news_title_input" name="news_title_input" placeholder="Pealkiri">
<br>
<label for="news_content_input">Uudise tekst</label>
<br>
<textarea id="news_content_input" name="news_content_input" placeholder="Uudise tekst" rows="6" cols="40"></textarea>
<br>
<label for="news_author">Uudise lisaja nimi</label>
<br>
<input type="text" id="news_author_input" name="news_author_input" placeholder="Nimi">
<br>
<input type="submit" name="news_submit" value="Salvesta uudis!">
</form>
<p><?php echo $news_input_error; ?></p>
</body>
</html>