Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $db = @new mysqli('localhost', 'root', '', 'temp');
- if ($db->connect_errno) {
- exit('Fehler: ' . $db->connect_error);
- }
- if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- try {
- $sql = 'INSERT INTO test (FirstName, LastName) VALUES (?, ?)';
- $stmt = $db->prepare($sql);
- $stmt->bind_param('ss', $_POST['FirstName'], $_POST['LastName']);
- if (!$stmt->execute()) {
- throw new Exception($db->error);
- } else {
- echo '<p>Eintrag erfolgreich!</p>';
- }
- }
- catch (Exception $e) {
- exit($e -> getMessage());
- }
- }
- ?>
- <form action="" method="post">
- Vorname: <input type="text" name="FirstName" /><br />
- Nachname: <input type="text" name="LastName" /><br />
- <input type="submit" value="Speichern" />
- </form>
Add Comment
Please, Sign In to add comment