verjaardagskalender

Gesponsorde koppelingen

PHP script bestanden

  1. verjaardagskalender

« Lees de omschrijving en reacties

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
<?
    // define table
    $table = "kalender";
    
    //-- DIT WERKT ALLEEN MET MYSQL!!!!
    //-- make database connection (if there's none yet) (or require db file)
    //-- fill this in yourself!

  
    $dbuser = "user"; // your mysql username
    $dbpass = "pass"; // your mysql password
    $dbhost = "localhost"; // the host you connect to
    $dbname = "database_name"; // your mysql database name
        
    //-- connect

    $dbconn = mysql_connect($dbhost, $dbuser, $dbpass);
    //-- select database
    mysql_select_db($dbname, $dbconn) or die(mysql_error());
    
    //-- end database connection
    //---------------------------------------------------
    
    //-- set year

    if (!$_POST['tyear'])
        $year = date('Y');
    else
        $year = $_POST['tyear'];
    
    //-- header
    echo "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "\">";
    echo "<B>Kalender " . $year . "</B> ";
    echo "<select name=\"tyear\">";
    
    //-- show years in dropdown menu
    for ($i = date('Y')-10; $i < date('Y')+10; $i++)
    {

        if ($i == $year)
            echo "<option value=\"" . $i . "\" selected>" . $i . "</option>";
        else
            echo "<option value=\"" . $i . "\">" . $i . "</option>";
    }

    echo "</select> ";
    echo "<input type=\"submit\" name=\"submit\" value=\"check\">";
    echo "</form><p>";
    
    //-- DIT WERKT ALLEEN MET MYSQL!!!!
    if ($_POST['jnaam'])
    {

        $gebdatum = $gebdd . "-" . $gebmm . "-" . $gebyy;
        
        $sql = "INSERT INTO " . $table . " (id, datum, naam) VALUES ('', '" . $gebdatum . "', '" . $_POST['jnaam'] . "')";
        $res = mysql_query($sql);
        
        if ($res)
        {

            echo "<b>" . $_POST['jnaam'] . "</b> toegevoegd.<p>";
        }

        else
        {
            echo "<B>" . $_POST['jnaam'] . "</b> niet toegevoegd.<p>";
        }
    }

    elseif ($_GET['id'])
    {

        $sql = "DELETE FROM " . $table . " WHERE id = '" . $_GET['id'] . "'";
        $res = mysql_query($sql);
        
        if ($res)
        {

            echo "<B>Verjaardag verwijderd.</b><p>";
        }

        else
        {
            echo "<b>Verjaardag kon nie verwijderd worden.</b><p>";
        }
    }

    //--------------------------------------------------
    
    echo "<table border=1 cellspacing=0 cellpadding=5><tr><td>";
    echo "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "\">";
    echo "<b>Verjaardag toevoegen</b><br>";
    echo "Naam: <input type=\"text\" name=\"jnaam\"><br>";
    echo "<select name=\"gebdd\">";
    for ($dd = 1; $dd <= 31; $dd++)
    {

        if ($dd < 10)
            $sd = "0" . $dd;
        else
            $sd = $dd;
        
        echo "<option value=\"" . $sd . "\">" . $sd . "</option>";
    }

    echo "</select> ";
    echo "<select name=\"gebmm\">";
    echo "<option value=\"01\">Jan</option>";
    echo "<option value=\"02\">Feb</option>";
    echo "<option value=\"03\">Mar</option>";
    echo "<option value=\"04\">Apr</option>";
    echo "<option value=\"05\">Mei</option>";
    echo "<option value=\"06\">Jun</option>";
    echo "<option value=\"07\">Jul</option>";
    echo "<option value=\"08\">Aug</option>";
    echo "<option value=\"09\">Sep</option>";
    echo "<option value=\"10\">Okt</option>";
    echo "<option value=\"11\">Nov</option>";
    echo "<option value=\"12\">Dec</option>";
    echo "</select>";
    
    echo "<select name=\"gebyy\">";
    for ($yy = date('Y')-80; $yy <= date('Y'); $yy++)
    {

        if ($yy == date(Y))
            echo "<option value=\"" . $yy . "\" selected>" . $yy . "</option>";
        else
            echo "<option value=\"" . $yy . "\">" . $yy . "</option>";
    }

    echo "</select> ";
    
    echo "<input type=\"submit\" value=\"toevoegen\" name=\"submit\">";
    echo "</form></td></tr></table><p>";

        //-- fetch birthday people from database
        $sql = "SELECT id,datum,naam FROM " . $table;
    $res = mysql_query($sql);
    
    $i = 1;
    while ($row = mysql_fetch_array($res))
    {

        $id[$i] = $row['id'];
        $birthday[$i] = $row['datum'];
        $name[$i] = $row['naam'];
        
        $i++;
    }

    unset($i);
    //--------------------------------------------

    //-- maanden

    $months[1] = "Januari";
    $months[2] = "Februari";
    $months[3] = "Maart";
    $months[4] = "April";
    $months[5] = "Mei";
    $months[6] = "Juni";
    $months[7] = "Juli";
    $months[8] = "Augustus";
    $months[9] = "September";
    $months[10] = "Oktober";
    $months[11] = "November";
    $months[12] = "December";
    
    //-- begin table
    echo "<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\">\n";
    echo "<tr>\n";
    echo "<th width=\"100\">Maand</th>\n";
    echo "<th width=\"100\">Naam</th>\n";
    echo "<th width=\"20\">Wordt</th>\n";
    echo "<th width=\"100\">Geb. datum</th>\n";
    echo "</tr>\n\n";
    
    //-- loop trough months
    for ($i = 1; $i <= count($months); $i++)
    {

        echo "<tr>\n";
        
        //-- check for current month
        if (date('m') < 10)
            $thismonth = substr(date('m'), 1, 1);
        else
            $thismonth = date('m');
            
        if ($thismonth == $i)
            echo "<td bgcolor=\"#cccccc\"><b>" . $months[$i] . "</b>";
        else
            echo "<td><b>" . $months[$i] . "</b>";
            
        echo "</td>";
        
        //-- loop trough birthdays
        for ($b = 1; $b <= count($birthday); $b++)
        {

            //-- check for the birthday month
            if (substr($birthday[$b], 3, 2) < 10)
                $setbirth = substr($birthday[$b], 4, 1);
            else
                $setbirth = substr($birthday[$b], 3, 2);
            
            if ($i == $setbirth)
            {

                $age = substr($birthday[$b], 6, 4);
                $age = $year - $age;
                
                //-- if no earlier birthdays given
                if (!$birthdays)
                {

                    echo "<td>[ <font color=\"#ff0000\"><a href=\"" . $_SERVER['PHP_SELF'] . "?id=" . $id[$b] . "\">del</a></font> ] | " . htmlentities($name[$b]) . "</td>\n";
                    echo "<td>" . $age . "</td>\n";
                    echo "<td>" . $birthday[$b] . "</td>\n";
                    echo "</tr>\n\n";
                    
                    $birthdays = 1;
                }

                //-- if first birthday of month already exists
                else
                {
                    echo "<tr>\n";
                    echo "<td>&nbsp;</td>\n";
                    echo "<td>[ <font color=\"#ff0000\"><a href=\"" . $_SERVER['PHP_SELF'] . "?id=" . $id[$b] . "\">del</a></font> ] | " . htmlentities($name[$b]) . "</td>\n";
                    echo "<td>" . $age . "</td>\n";
                    echo "<td>" . $birthday[$b] . "</td>\n";
                    echo "</tr>\n\n";
                }
            }
        }

        
        // no birthday message
        if (!$birthdays)
        {

            echo "<td><i>Geen verjaardagen</i></td>\n";
            echo "<td>&nbsp;</td>\n";
            echo "<td>&nbsp;</td>\n";
            echo "</tr>\n\n";
        }

        
        unset($birthdays);
    }


?>

 
 

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.