klein-forum-met-mysql

Gesponsorde koppelingen

PHP script bestanden

  1. klein-forum-met-mysql

« Lees de omschrijving en reacties

<html>
<head>
<title>Forum</title>
<style>
TD {
font-family: Verdana, arial, helvetica;
font-size: 13px;
}
BODY {
font-family: Verdana, arial, helvetica;
font-size: 13px;
}
.small {
font-size: 9px;
}
</style>
</head>
<body bgcolor="#d7d7d7" link="#ff0000" vlink="#ff0000" alink="#ff0000">
<center>

Code (php)
PHP script in nieuw venster Selecteer het PHP script
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
<?

    // ===========================
    // forum in shape of guestbook
    // ===========================
    
    // variables
    // set table of database

    $table = "vb_forum";
    // set webmaster's e-mail address
    $set_email = "[email protected]";
    // set name of forum
    $set_forum = "Het DOMEIN forum";
    // set color for name of forum
    $set_head = "<font color=\"#006600\">";
    $set_head2 = "</font>";
    // main topic (leave blanc for no styles)
    $set_main = "<b>";
    $set_main2 = "</b>";
    // replies (leave blanc for no styles)
    $set_reply = "";
    $set_reply2 = "";
    // decide date style (leave blanc for no styles)
    $set_date = "<span class=\"small\"><i>";
    $set_date2 = "</i></span>";
    // decide name style (leave blanc for no style)
    $set_name = "<font color=\"blue\">";
    $set_name2 = "</font>";
    // set bgcolor of active title bar
    $set_title = "#cccfff";
    // set bgcolor of inactive title bar
    $set_titlebar = "#cccccc";
    // give border color for bottom volgende/volgende page
    $set_bcolor = "#000000";
    // show (define here) threads per page
    $set_next = "15";
    // define image path ZONDER SLASH!!!!!
    $set_path = "imgs";
    
    // make database connection
    $host = "localhost";
    $user = "mysqluser";
    $pass = "mysqlpass";
    $dbdb = "databasename";
    
    // check if database connection's valid
    if (!mysql_select_db($dbdb, mysql_connect($host, $user, $pass)))
    {

        echo "Er kon geen connectie gemaakt worden met de database.<P>";
        
        echo "Probeer het opnieuw, of waarschuw de webmaster op $set_email.<p>";
        exit();
    }

    
    // echo name of forum
    echo "<h2>$set_head" . "$set_forum" . "$set_head2</h2>";
    
    if (!$_GET["cat"])
        $cat = 1;
    else
        $cat = $_GET[cat];
    
    echo "<table width=\"500\" border=\"0\" cellspacing=\"10\" cellpadding=\"0\">";
    echo "<tr valign=\"top\">";
    echo "<td width=\"10%\">";
    
    //===============================
    // show overview
    //===============================

    
    if (!$_GET["id"] && !$_GET["add"] && !$_POST["add"] && !$_POST["id"])
    {

    
        // set threads
        if (!$_GET["p"])
            $p = "0";
        else
            $p = $_GET[p];
            
        echo "<p><a href=" . $_SERVER['PHP_SELF'] . "?add=1>Voeg een nieuw bericht toe</a></p>";
        
        // check for threads
        $sql = "select id from $table where rid = '' and cat = $cat";
        $res = mysql_query($sql);
        $threads = mysql_num_rows($res);
        
        // unset vars
        $sql = "";
        $res = "";
        
        // show topics with replies
        $sql = "SELECT * FROM $table WHERE rid = '' AND cat = '$cat' ORDER BY id DESC LIMIT $p,$set_next";
        $res = mysql_query($sql);
        $thispage = mysql_num_rows($res);
        
        // show vorige / volgende    
        if (($threads > $p) && ($thispage >= $set_next))
        {

            echo "<table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\">";
            echo "<tr>";
            echo "<td align=left>";
            
            if (!$p)
                echo "<a href=" . $_SERVER['PHP_SELF'] . "?p=$set_next&cat=$cat><img src=$set_path/arrow_left.gif border=0></a> <a href=\"" . $_SERVER['PHP_SELF'] . "?p=$set_next&cat=$cat\">vorige</a>";
            else
            {
                $next = $p - $set_next;
                $p = $p + $set_next;
                echo "<a href=" . $_SERVER['PHP_SELF'] . "?p=$p&cat=$cat><img src=$set_path/arrow_left.gif border=0></a> <a href=\"" . $_SERVER['PHP_SELF'] . "?p=$p&cat=$cat\">vorige</a> | ";
                echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?p=$next&cat=$cat\">volgende</a> <a href=" . $_SERVER['PHP_SELF'] . "?p=$next&cat=$cat><img src=$set_path/arrow.gif border=0></a>";
            }

                        
            echo "</tr>";
            echo "</table><p>";
        }

        elseif ($p)
        {

            echo "<table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\">";
            echo "<tr>";
            echo "<td align=left>";
            $p = $p - $set_next;
            echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?p=$p&cat=$cat\">volgende</a> <a href=" . $_SERVER['PHP_SELF'] . "?p=$p&cat=$cat><img src=$set_path/arrow.gif border=0></a>";
            echo "</td></tr>";
            echo "</table>";
        }

        
        // begin table for threads
        echo "<table width=\"100%\" border=\"1\" cellpadding=\"8\" cellspacing=\"0\">";
        echo "<tr>";
        echo "<td>";
        echo "<table border=0 cellspacing=0 cellpadding=0>\n";

        // loop trough results
        while ($row = mysql_fetch_array($res))
        {

            $row[title] = htmlentities($row[title]);
            $row[title] = nl2br($row[title]);
            $row[name] = htmlentities($row[name]);
            $row[name] = nl2br($row[name]);
        
            echo "<tr><td colspan=\"2\">$set_main<a href=\"" . $_SERVER['PHP_SELF'] . "?id=$row[id]&p=$p&cat=$cat\">$row[title]</a>$set_main2 - $set_name" . "$row[name]" . "$set_name2 $set_date" . "$row[date]" . "$set_date2</td></tr>\n";
            
            $r_sql = "SELECT * FROM $table WHERE rid = $row[id] AND cat = $cat ORDER BY id";
            $r_res = mysql_query($r_sql);
            
            if ($r_res)
            {

                while ($r_row = mysql_fetch_array($r_res))
                {

                    $r_row[title] = htmlentities($r_row[title]);
                    $r_row[title] = nl2br($r_row[title]);
                    $r_row[name] = htmlentities($r_row[name]);
                    $r_row[name] = nl2br($r_row[name]);
                    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>$set_reply<a href=\"" . $_SERVER['PHP_SELF'] . "?id=$r_row[id]&rid=$r_row[rid]&p=$p&cat=$cat\">$r_row[title]</a>$set_reply2 - $set_name" . "$r_row[name]" . "$set_name2 $set_date" . "$r_row[date]" . "$set_date2</td></tr>\n";
                }
            }

            
            echo "<tr><td colspan=\"2\">&nbsp;</td></tr>\n";
        }

        
        echo "</table>\n";
        echo "</td></tr></table>";
        
        
        // show vorige / volgende    
        if (($threads > $p) && ($thispage >= $set_next))
        {

            echo "<table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\">";
            echo "<tr>";
            echo "<td align=left>";
            
            if (!$p)
                echo "<a href=" . $_SERVER['PHP_SELF'] . "?p=$set_next&cat=$cat><img src=$set_path/arrow_left.gif border=0></a> <a href=\"" . $_SERVER['PHP_SELF'] . "?p=$set_next&cat=$cat\">vorige</a>";
            else
            {
                echo "<a href=" . $_SERVER['PHP_SELF'] . "?p=$p&cat=$_GET[cat]><img src=$set_path/arrow_left.gif border=0></a> <a href=\"" . $_SERVER['PHP_SELF'] . "?p=$p&cat=$cat\">vorige</a> | ";
                echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?p=$next&cat=$_GET[cat]\">volgende</a> <a href=" . $_SERVER['PHP_SELF'] . "?p=$next&cat=$_GET[cat]><img src=$set_path/arrow.gif border=0></a>";
            }

                        
            echo "</tr>";
            echo "</table><p>";
        }

        elseif ($p)
        {

            echo "<table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\">";
            echo "<tr>";
            echo "<td align=left>";
            echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?p=$p&cat=$cat\">volgende</a> <a href=" . $_SERVER['PHP_SELF'] . "?p=$p&cat=$cat><img src=$set_path/arrow.gif border=0></a>";
            echo "</td></tr>";
            echo "</table>";
        }
    }

    
    //===============================
    // show details
    //===============================

    
    elseif ($_GET["id"] && !$_GET["add"] && !$_POST["add"])
    {

        $sql = "select * from $table where id = $id";
        $res = mysql_query($sql);
        $row = mysql_fetch_array($res);
        
        $holdid = $row[id];
        
        $row[msg] = htmlentities($row[msg]);    
        $row[msg] = nl2br($row[msg]);
        $row[title] = htmlentities($row[title]);    
        $row[title] = nl2br($row[title]);
        $row[name] = htmlentities($row[name]);    
        $row[name] = nl2br($row[name]);
        
        
        
        if (!$row[email] || !strpos($row[email], "@") && !is_numeric($row[email]))
            $author = "$row[name]";
        elseif (is_numeric($row[email]))
            $author = "<a href=\"$path/profile/?id=$row[email]\">$row[name]</a>";
        else
            $author = "<a href=\"mailto:$row[email]\">$row[name]</a>";
            
        if ($rid)
            $holdit = $rid;
        else
            $holdit = $id;
                
        echo "<table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\">";
        echo "<tr>";
        echo "<td align=left><a href=" . $_SERVER['PHP_SELF'] . "?add=1&id=$holdit&p=$p&cat=$cat><img src=$set_path/arrow.gif border=0></a> <a href=\"" . $_SERVER['PHP_SELF'] . "?add=1&id=$holdit&p=$p&cat=$cat\">Reageer op dit bericht</a></td>";
        echo "</tr>";
        echo "</table><p>";
        
        echo "<table width=\"100%\" border=\"1\" cellpadding=\"8\" cellspacing=\"0\">";
        echo "<tr>";
        echo "<td>";
        echo "<table border=0 cellspacing=0 cellpadding=0 width=\"100%\">";
        echo "<tr><td height=\"20\" bgcolor=\"$set_title\"><b>$row[title] | $author | $row[date]</b></td></tr>";
        echo "<tr><td>$row[msg]</td></tr>";
        echo "</table><p>";
        echo "</td></tr></table><p>";
        
        $sql = "";
        $res = "";
        $row = "";
        
        echo "<table border=0 cellspacing=0 cellpadding=0 width=\"100%\">";
        echo "<tr><td height=\"20\" bgcolor=\"$set_titlebar\">Berichten overzicht</td></tr>";
        
        // get main topic
        if ($rid)
            $h_sql = "select id,title,name,date from $table where id = $rid AND cat = '$cat'";
        else
            $h_sql = "select id,title,name,date from $table where id = $holdid AND cat = '$cat'";
        $h_res = mysql_query($h_sql);
        $h_row = mysql_fetch_array($h_res);
        
        $h_row[title] = htmlentities($h_row[title]);    
        $h_row[title] = nl2br($h_row[title]);
        $h_row[name] = htmlentities($h_row[name]);    
        $h_row[name] = nl2br($h_row[name]);
        
        if ($h_row[id] == $holdid)
            echo "<tr><td><img src=\"$set_path/arrow.gif\"> $set_reply<a href=\"" . $_SERVER['PHP_SELF'] . "?id=$h_row[id]&rid=$h_row[rid]&p=$p&cat=$cat\">$h_row[title]</a>$set_reply2 - $set_name" . "$h_row[name]" . "$set_name2 $set_date" . "$h_row[date]" . "$set_date2</td></tr>\n";
        else
            echo "<tr><td>$set_reply<a href=\"" . $_SERVER['PHP_SELF'] . "?id=$h_row[id]&rid=$h_row[rid]&p=$p&cat=$cat\">$h_row[title]</a>$set_reply2 - $set_name" . "$h_row[name]" . "$set_name2 $set_date" . "$h_row[date]" . "$set_date2</td></tr>\n";
        
        // mysql for reactions
        if ($rid)
            $sql = "select id,title,name,date,rid from $table where rid = $rid and cat = $cat ORDER BY id";
        else
            $sql = "select id,title,name,date,rid from $table where rid = $id and cat = $cat ORDER BY id";
        $res = mysql_query($sql);
        
        if (mysql_num_rows($res) >= 1)
        {

            while ($row = mysql_fetch_array($res))
            {
        
                $row[title] = htmlentities($row[title]);    
                $row[title] = nl2br($row[title]);
                $row[name] = htmlentities($row[name]);    
                $row[name] = nl2br($row[name]);
                        
                // show reactions on it
                
                if ($row[id] == $holdid)
                    echo "<tr><td><img src=\"$set_path/arrow.gif\"> $set_reply<a href=\"" . $_SERVER['PHP_SELF'] . "?id=$row[id]&rid=$row[rid]&p=$p&cat=$cat\">$row[title]</a>$set_reply2 - $set_name" . "$row[name]" . "$set_name2 $set_date" . "$row[date]" . "$set_date2</td></tr>\n";
                else
                    echo "<tr><td>$set_reply<a href=\"" . $_SERVER['PHP_SELF'] . "?id=$row[id]&rid=$row[rid]&p=$p&cat=$cat\">$row[title]</a>$set_reply2 - $set_name" . "$row[name]" . "$set_name2 $set_date" . "$row[date]" . "$set_date2</td></tr>\n";
            }
        }

        else
        {
            echo "<tr><td>&nbsp;</td></tr>";
            echo "<tr><td><b><i>Er zijn nog geen reacties op dit bericht</a></td></tr>\n";
        }

        
        echo "</table>";
        
        echo "<p>&nbsp;</p>";
        
        if ($rid)
            $holdit = $rid;
        else
            $holdit = $id;
        
        echo "<table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\">";
        echo "<tr>";
        echo "<td align=left><a href=" . $_SERVER['PHP_SELF'] . "?p=$p&cat=$cat><img src=$set_path/arrow_left.gif border=0></a> <a href=\"" . $_SERVER['PHP_SELF'] . "?p=$p&cat=$cat\">Vorige pagina</a> <a href=" . $_SERVER['PHP_SELF'] . "?add=1&id=$holdit&p=$p&cat=$cat><img src=$set_path/arrow.gif border=0></a> <a href=\"" . $_SERVER['PHP_SELF'] . "?add=1&id=$holdit&p=$p&cat=$cat\">Reageer op dit bericht</a></td>";
        echo "</tr>";
        echo "</table><p>";
    }

    
    //===============================
    // add thread or reply
    //===============================

    
    elseif ($_GET["add"] || $_POST["add"])
    {

        if ($_POST["submit"] && ($_POST["name"] && $_POST["title"] && $_POST["msg"]))
        {

            // set date
            $date = date("d.m.Y [H:i]");
            
            $sql = "INSERT INTO $table (id, name, email, title, msg, date, rid, cat) VALUES ('', '$_POST[name]', '$POST[email]', '$_POST[title]', '$_POST[msg]', '$date', '$rid', '$cat')";
            $res = mysql_query($sql);
            
            if ($res)
            {

                
                echo "<table width=\"100%\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\">";
                echo "<tr>";
                echo "<td>";
                echo "Bedankt voor je bericht <b>$_POST[name]</b>!!<p>";
                
                if ($rid)
                    echo "<a href=" . $_SERVER['PHP_SELF'] . "?p=$p&id=$rid&cat=$cat><img src=$set_path/arrow_left.gif border=0></a> <a href=" . $_SERVER['PHP_SELF'] . "?id=$rid&p=$p&cat=$cat>Ga terug naar het bericht</a>";
                else
                    echo "<a href=" . $_SERVER['PHP_SELF'] . "?p=$p&cat=$cat><img src=$set_path/arrow_left.gif border=0></a> <a href=" . $_SERVER['PHP_SELF'] . "?p=$p&cat=$cat>Ga terug naar de berichten</a>";
                
                echo "</td>";
                echo "</tr>";
                echo "</table><p>";
            }

            else
            {
                echo "Je bericht kon niet worden toegevoegd, probeer het opnieuw.";
            }
        }

        else
        {
            if ($_GET["id"] || $_POST["id"])
            {

                if ($_GET["id"])
                    $sql = "SELECT title FROM $table WHERE id = $_GET[id]";
                else
                    $sql = "SELECT title FROM $table WHERE id = $_POST[id]";
                    
                $res = mysql_query($sql);
                
                if (substr(mysql_result($res, 0), 0, 3) != "Re:")
                    $title = "Re: " . mysql_result($res, 0);
                else
                    $title = mysql_result($res, 0);
            }

            
            if ($_POST["submit"] && (!$_POST["name"] || !$_POST["title"] || !$_POST["msg"]))
            {

                $err = "<b>Je bent vergeten enkele velden in te vullen</b><p>";
            }

            
            echo "<table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\">";
            echo "<tr>";
            echo "<td align=left>";
            
            if ($id)
                echo "<a href=" . $_SERVER['PHP_SELF'] . "?id=$id&cat=$cat&p=$p><img src=$set_path/arrow_left.gif border=0></a> <a href=\"" . $_SERVER['PHP_SELF'] . "?id=$id&cat=$cat&p=$p\">terug naar het bericht</a></a>";
            else
                echo "<a href=" . $_SERVER['PHP_SELF'] . "&cat=$cat&p=$p><img src=$set_path/arrow_left.gif border=0></a> <a href=\"" . $_SERVER['PHP_SELF'] . "?&cat=$cat&p=$p\">terug naar de berichten</a></a>";
            
            echo "</td>";
            echo "</tr>";
            echo "</table><p>";
            
            // begin table with form
            echo "<table width=\"100%\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\">";
            echo "<tr>";
            echo "<td>";
            
            echo "<p>&nbsp;</p>";
            
            echo "<p>&nbsp;</p>";
            
            echo "<table border=0 cellspacing=0 cellpadding=0 border=0>\n";
            
            echo "<tr><td>$err</td></tr>";
            
            echo "<tr><td>";            
            
            echo "<form method=post action=" . $_SERVER['PHP_SELF'] . ">";
            echo "<input type=hidden name=add value=1>";
            if ($_GET["id"] || $_POST["id"])
            {

                if ($_GET["id"])
                    echo "<input type=hidden name=rid value=$_GET[id]>";
                else
                    echo "<input type=hidden name=rid value=$_POST[id]>";
            }

            else
            {
                if ($_GET["rid"])
                    echo "<input type=hidden name=rid value=$_GET[rid]>";
                else
                    echo "<input type=hidden name=rid value=$_POST[rid]>";
            }

            
            if ($_GET["p"])
                echo "<input type=hidden name=p value=$_GET[p]>";
            else
                echo "<input type=hidden name=p value=$_POST[p]>";
                
            if ($_GET["cat"])
                echo "<input type=hidden name=cat value=$_GET[cat]>";
            else
                echo "<input type=hidden name=cat value=$_POST[cat]>";
                
            echo "<b>Naam*:</b><br>";
            echo "<input type=text name=name value=\"$_POST[name]\" $disabled><p>";
            
            if (!$disabled)
            {

                echo "<b>Email</b><br>";
                echo "<input type=text name=email value=\"$_POST[email]\"><p>";
            }

            
            echo "<b>Titel*</b><br>";
            if ($title)
                echo "<input type=text name=title value=\"$title\"><p>";
            else
            {
                if ($_GET["title"])
                    echo "<input type=text name=title value=\"$_GET[title]\"><p>";
                else
                    echo "<input type=text name=title value=\"$_POST[title]\"><p>";
            }

            
            echo "<b>Bericht*</b><br>";
            echo "<textarea name=msg cols=55 rows=6>$_POST[msg]</textarea><p>";
            
            echo "<input type=submit name=submit value=\"Plaats bericht!\"><p>";
            echo "</form>";
            
            echo "</td></tr>";
            echo "</table>";
            
            
            echo "<p>&nbsp;</p>";
                
            echo "</td>";
            echo "</tr>";
            echo "</table><P>";
        }
    }


    echo "</td></tr></table>";
?>

</body>
</html>

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.