Advertisement
Guest User

Untitled

a guest
Jun 13th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 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="text" name="ID" value="" /><br />
  23. <input type="submit" name="new" value="Neuer Datensatz" />
  24. </form>
  25.  
  26. <table border="3">
  27. <tr>
  28. <td>Neue ID</td>
  29. <td>ID</td>
  30. <td>Nachname</td>
  31. <td>Vorname</td>
  32. <td>Strasse</td>
  33. <td>PLZ</td>
  34. <td>Ort</td>
  35. </tr>
  36.  
  37. <?PHP
  38. $sql="SELECT * FROM tkunde";
  39. $stmt=$db -> prepare($sql);
  40. //$stmt->bindValue('fbn',$_POST['benutzername'],PDO::PARAM_STR);
  41. //$stmt->bindValue('fpw',$_POST['passwort'],PDO::PARAM_STR);
  42. $stmt -> execute();
  43. $anzahl=$stmt->rowCount();
  44.  
  45. while($row = $stmt -> fetch(PDO::FETCH_ASSOC)) {
  46. echo "<tr>";
  47. ?> <td>
  48. <form method="POST" action="">
  49. <input type="text" name="ID" />
  50. </form>
  51. </td>
  52. <?PHP
  53. echo "<td>" .$row['KU_ID'] ."</td>";
  54. echo "<td>" .$row['Nachname'] ."</td>";
  55. echo "<td>" .$row['Vorname'] ."</td>";
  56. echo "<td>" .$row['Strasse'] ."</td>";
  57. echo "<td>" .$row['PLZ'] ."</td>";
  58. echo "<td>" .$row['Ort'] ."</td>";
  59. echo "<tr>";
  60. }
  61.  
  62. if(isset($_POST['new'])){
  63. ?>
  64. <form method="POST" action="">
  65. Nachname: <input type="text" name="nn" />
  66. Vorname: <input type="text" name="vn" />
  67. Strasse: <input type="text" name="strasse" />
  68. PLZ: <input type="text" name="plz" />
  69. Ort: <input type="text" name="ort" />
  70. <br /><br />
  71. <input type="submit" name="send" value="Absenden" />
  72. <br /><br />
  73. </form>
  74.  
  75. <?PHP
  76. }
  77. if(isset($_POST['send'])){
  78. if($_POST['nn']!=""){
  79. $sql1="INSERT INTO tkunde (Nachname, Vorname, Strasse, Plz, Ort) VALUES (:nn, :vn, :strasse, :plz, :ort)";
  80. $stmt1=$db -> prepare($sql1);
  81.  
  82. $stmt1->bindValue('id',$_POST['ID'],PDO::PARAM_STR);
  83. $stmt1->bindValue('nn',$_POST['nn'],PDO::PARAM_STR);
  84. $stmt1->bindValue('vn',$_POST['vn'],PDO::PARAM_STR);
  85. $stmt1->bindValue('strasse',$_POST['strasse'],PDO::PARAM_STR);
  86. $stmt1->bindValue('plz',$_POST['plz'],PDO::PARAM_STR);
  87. $stmt1->bindValue('ort',$_POST['ort'],PDO::PARAM_STR);
  88.  
  89. $stmt1 -> execute();
  90.  
  91. }
  92. }
  93.  
  94. ?>
  95. </table>
  96. </body>
  97. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement