-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd.php
79 lines (71 loc) · 2.26 KB
/
add.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
<html lang="pl">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="add_wpis">
<h1>DODAJ WPIS</h1>
</div>
<div id="add_form">
<form action="" method="post">
<table>
<tr><td>Temat:</td><td><input type="text" name="temat" id="i1" maxlength="255"></td></tr>
<tr><td>Wiadomosc: </td><td><textarea name="wpis" id="i2" maxlength="255"></textarea></td></tr>
<tr><td></td><td><input type="submit" value="Dodaj" class="submit2"></td></tr>
</table>
</form>
<b><u><p id="powrot" style="text-align: center; color: #24292f;"><a href="logowanie.php">Powrót do strony głównej.</a></p></u></b>
</div>
<?php
include 'test.php';
class Wpis
{
public $wpis;
public $temat;
public $nick;
public function __construct($a,$b,$c)
{
$this->wpis=$a;
$this->temat=$b;
$this->nick=$c;
if ($this->nick=='')
{
$this->nick='Anonim';
}
if ($this->temat=='')
{
$this->temat='(Brak tematu.)';
}
}
public function dodaj()
{
global $conn;
$q = "INSERT INTO wpisy VALUES (NULL,'$this->nick','$this->temat','$this->wpis')";
$result = $conn->query($q) or die ("Błąd");
}
public function czy_puste()
{
if(empty($_POST['wpis'])) return 0;
else return 1;
}
}
if(!empty($_POST['wpis']) && !empty($_POST['temat'])) {
$dodaj = new Wpis($_POST['wpis'], $_POST['temat'], $_SESSION['user']);
if ($dodaj->czy_puste() == 1) {
$dodaj->dodaj();
if ($_SESSION['start'] == 1) header('Location: logowanie.php');
else header('Location: main.php');
} else exit();
}
else{
echo '<b><p style="text-align: center;">Proszę uzupełnić dane.</p></b>';
}
?>
<br/>
<footer>
<a href="https://github.com/zdinozi" target="_blank"><img src="github-ww.png" style="width: 50px; height: 50px;"></a>
<a href="https://www.linkedin.com/in/wiktor-banasiak-672425222/" target="_blank"><img src="linkedin.png" style="width: 50px; height: 50px;"></a>
</footer>
</body>
</html>