]> git.treefish.org Git - banana.git/blob - register.php
...
[banana.git] / register.php
1 <?php
2 require 'include/head.inc';
3
4 if(isset($_POST['submit']) && $_POST['firstname']!="" && $_POST['lastname']!="" 
5                            && $_POST['mnumber']!="" && $_POST['email']!="" && $_POST['password']!="")
6 {
7   $firstname = $_POST['firstname'];
8   $lastname = $_POST['lastname'];
9   $mnumber = $_POST['mnumber'];
10   $email = $_POST['email'];
11   $password = $_POST['password'];
12
13   require 'include/db.inc';
14
15   // user already exists //
16   if($db->query("SELECT COUNT(*) FROM students WHERE mnumber = $mnumber")->fetch(PDO::FETCH_NUM)[0] == 1) {
17     print "<table bgcolor=\"red\">";
18       print "<tr><th><b><font color=\"white\">user already registered</font></b></th><tr>";
19     print "</table>";
20     break;
21   }
22
23   $db->query("INSERT INTO students (mnumber,firstname,lastname,email,password) 
24         VALUES (\"$mnumber\",\"$firstname\",\"$lastname\",\"$email\",\"$password\")");
25
26   print "<table bgcolor=\"lightgreen\">";
27     print "<tr><th><b><font color=\"white\">registration successfull</font></b></th><tr>";
28   print "</table>";
29
30   echo "$firstname $lastname was successfully registered.<br>";
31
32   // send password-email //
33   $lec_lines = file('var/lecture.txt');
34   foreach ($lec_lines as $line_num => $line) {
35     $lecture[$line_num] = $line;
36   }
37   $nachricht = "Hello $firstname($mnumber)!\nYou registered for " . trim($lecture[0]) . " " . trim($lecture[1]) . ".\nRemember your password: $password\n\nYours,\nBanana.";
38   //$nachricht = wordwrap($nachricht,70);
39   $empfaenger = 'niemand@example.com';
40   $betreff = 'Der Betreff';
41   $header = 'From: banana@treefish.org' . "\r\n" .
42     'Reply-To: noreply@treefish.org' . "\r\n" .
43     'X-Mailer: PHP/' . phpversion();
44   mail($email, "Banana Registration: " . trim($lecture[0]) . " " . trim($lecture[1]), $nachricht, $header);
45
46   break;
47 }
48 ?>
49
50 <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
51   <table bgcolor="black">
52     <tr><th><b><font color="white">registration</font></b></th><tr>
53   </table>
54
55   <table>
56     <tr>  
57       <th align="left">First name:</th> <th><input type="text" name="firstname"></th>
58     </tr>
59     <tr>  
60       <th align="left">Last name:</th> <th><input type="text" name="lastname"></th>
61     </tr>
62     <tr>  
63       <th align="left">Mat.nummer:</th> <th><input type="text" name="mnumber"></th>
64     </tr>
65     <tr>  
66       <th align="left">Email:</th> <th><input type="text" name="email"></th>
67     </tr>
68     <tr>  
69       <th align="left">Password:</th> <th><input type="text" name="password"></th>
70     </tr>
71   
72     <tr>
73       <th></th> <th align="right"><input type="submit" name="submit" value="Register"></th>
74     </tr>
75   </table>
76 </form>