Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!Doctype HTML>
- <html>
- <head>
- <title>Aufgabe 2</title>
- <meta charset="UTF-8">
- <link rel="stylesheet" type="text/css" href="index.css">
- </head>
- <body>
- <h1 style="text-decoration: underline">Mitarbeiter</h1>
- <form method="post" action="" id="list" name="list">
- <select name="list" id="list" size="15%" style="width: 40%;">
- <?php $c = new Main(); $c->Refresh(); ?>
- </select>
- </form>
- <br>
- <br>
- <form method="post" action="index.php">
- <a class="inputbox">ID:</a><br> <input type="number" name="id" id="id"><br>
- <a class="inputbox" name="forename">Forename:</a><br> <input type="text" name="forename" id="forename"><br>
- <a class="inputbox" name="name">Name:</a><br> <input type="text" name="name" id="name"><br>
- <a class="inputbox" name="city">City:</a><br> <input type="text" name="city" id="city"><br><br>
- <button type="submit" name="sent" id="sent" value="sent">HinzufΓΌgen</button>
- </form>
- </body>
- </html>
- <?php
- class Main
- {
- public $servername = "localhost";
- public $username = "admin";
- public $password = "admin";
- public $dbname = "aufgabe02";
- public $edit = false;
- function Refresh()
- {
- $con = new mysqli($this->servername, $this->username, $this->password, $this->dbname);
- if(!$con)
- {
- die("Connection Problem: ". $con->connect_error);
- }
- $sql = "SELECT * FROM aufgabe02.employee";
- $result = $con->query($sql);
- if(!$result)
- {
- die("SQL Problem: ". $con->error);
- }
- if ($result->num_rows > 0)
- {
- while ($row = $result->fetch_assoc())
- {
- $option = $row["id"] . " " . $row["forename"] . " " . $row["name"] . " " . $row["city"];
- echo "<option>" . $option . "</option>";
- }
- }
- $con->close();
- }
- function AddUser($id, $forename, $name, $city)
- {
- $con = new mysqli($this->servername, $this->username, $this->password, $this->dbname);
- if(!$con)
- {
- die("Connection Problem: ". $con->connect_error);
- }
- $sql = "INSERT INTO aufgabe02.employee (id, forename, name, city) VALUES ('".$id."', '".$forename."', '".$name."', '".$city."')";
- if (!$con->query($sql) === TRUE)
- {
- echo "Error: " . $sql . "<br>" . $con->error;
- }
- $con->close();
- $this->edit = false;
- }
- }
- if(isset($_POST['sent']) && !empty($_POST["sent"]))
- {
- $id = $_POST["id"];
- $forename = $_POST["forename"];
- $name = $_POST["name"];
- $city = $_POST["city"];
- if(preg_match("/^[1-9]+$/", $id) && preg_match("/^[a-zA-Z]+$/", $forename) && preg_match("/^[a-zA-Z]+$/", $name) && preg_match("/^[a-zA-Z]+$/", $city))
- {
- $t = new Main();
- if($t->edit)
- {
- $t->AddUser("edit", "edit", "edit", "edit");
- }
- else
- {
- $t->AddUser($id, $forename, $name, $city);
- }
- }
- }
- ?>
Add Comment
Please, Sign In to add comment