Advertisement
Guest User

Untitled

a guest
Jun 1st, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. <?PHP
  2. $db_host="localhost";
  3. $db_user="root";
  4. $db_password="";
  5. $db_name="versandhandel";
  6.  
  7. $db=new PDO("mysql:host=$db_host; dbname=$db_name; charset=utf8", $db_user, "");
  8. $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  9. print_r($_POST);
  10. print_r($_GET);
  11. ?>
  12.  
  13. <!DOCTYPE html>
  14. <html>
  15. <head>
  16. <meta charset="utf-8" />
  17. <title> </title>
  18. </head>
  19. <body>
  20. <h3>crud</h3>
  21. <form method="POST" action="">
  22. <input type="submit" name="new" value="Neuer Datensatz" />
  23. </form>
  24.  
  25. <table border="3">
  26. <tr>
  27. <td>Nachname</td>
  28. <td>Vorname</td>
  29. <td>Strasse</td>
  30. <td>PLZ</td>
  31. <td>Ort</td>
  32. </tr>
  33.  
  34. <?PHP
  35. $sql="SELECT * FROM tkunde";
  36. $stmt=$db -> prepare($sql);
  37. //$stmt->bindValue('fbn',$_POST['benutzername'],PDO::PARAM_STR);
  38. //$stmt->bindValue('fpw',$_POST['passwort'],PDO::PARAM_STR);
  39. $stmt -> execute();
  40. $anzahl=$stmt->rowCount();
  41.  
  42. while($row = $stmt -> fetch(PDO::FETCH_ASSOC)) {
  43. echo "<tr>";
  44. echo "<td>" .$row['Nachname'] ."</td>";
  45. echo "<td>" .$row['Vorname'] ."</td>";
  46. echo "<td>" .$row['Strasse'] ."</td>";
  47. echo "<td>" .$row['PLZ'] ."</td>";
  48. echo "<td>" .$row['Ort'] ."</td>";
  49. echo "<tr>";
  50. }
  51.  
  52. if(isset($_POST['new'])){
  53. ?>
  54. <form method="POST" action="">
  55. Nachname: <input type="text" name="nn" />
  56. Vorname: <input type="text" name="vn" />
  57. Strasse: <input type="text" name="strasse" />
  58. PLZ: <input type="text" name="plz" />
  59. Ort: <input type="text" name="ort" />
  60. <br /><br />
  61. <input type="submit" name="send" value="Absenden" />
  62. <br /><br />
  63. </form>
  64.  
  65. <?PHP
  66. if(isset($_POST['send'])){
  67. if($_POST['nn']!=""){
  68. $sql1="INSERT INTO tkunde (Nachname, Vorname, Strasse, Plz, Ort) VALUES (':nn',':vn',':strasse',':plz',':ort')";
  69. $stmt1=$db -> prepare($sql1);
  70.  
  71. $stmt1->bindValue('nn',$_POST['nn'],PDO::PARAM_STR);
  72. $stmt1->bindValue('vn',$_POST['vn'],PDO::PARAM_STR);
  73. $stmt1->bindValue('strasse',$_POST['strasse'],PDO::PARAM_STR);
  74. $stmt1->bindValue('plz',$_POST['plz'],PDO::PARAM_STR);
  75. $stmt1->bindValue('ort',$_POST['ort'],PDO::PARAM_STR);
  76.  
  77. $stmt1 -> execute();
  78. }
  79. }
  80. }
  81. ?>
  82. </table>
  83. </body>
  84. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement