Guest User

Untitled

a guest
Jan 21st, 2018
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.73 KB | None | 0 0
  1. <?php
  2.  
  3. $db = @new mysqli('localhost', 'root', '', 'temp');
  4.  
  5. if ($db->connect_errno) {
  6.     exit('Fehler: ' . $db->connect_error);
  7. }
  8.  
  9. if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  10.     try {
  11.         $sql = 'INSERT INTO test (FirstName, LastName) VALUES (?, ?)';
  12.         $stmt = $db->prepare($sql);
  13.         $stmt->bind_param('ss', $_POST['FirstName'], $_POST['LastName']);
  14.        
  15.         if (!$stmt->execute()) {
  16.             throw new Exception($db->error);
  17.         } else {
  18.             echo '<p>Eintrag erfolgreich!</p>';
  19.         }
  20.     }
  21.     catch (Exception $e) {
  22.         exit($e -> getMessage());
  23.     }
  24. }
  25.  
  26. ?>
  27.  
  28. <form action="" method="post">
  29.     Vorname: <input type="text" name="FirstName" /><br />
  30.     Nachname: <input type="text" name="LastName" /><br />
  31.     <input type="submit" value="Speichern" />
  32. </form>
Add Comment
Please, Sign In to add comment