Guest User

Untitled

a guest
Sep 29th, 2016
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. <?php
  2. error_reporting(0);
  3.  
  4. $servername = "localhost";
  5. $username = "root";
  6. $password = "";
  7. $datenbank = "formular";
  8.  
  9. $suche1 = 1;
  10. $suche2 = "vorname";
  11. ?>
  12.  
  13. <html>
  14. <head>
  15. <title>Datenbank-Abfrage</title>
  16. </head>
  17. <body>
  18. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
  19. <p>Suche: <input type="text" name="eingabe" style="width: 300px;" /> <input type="submit" name="senden" value="Senden" /></p>
  20. <p>
  21. <fieldset>
  22. <input type="radio" id="volleeingabe" name="suche1" value="1" checked="checked" /> <label for="volleeingabe">Volle Eingabe</label><br />
  23. <input type="radio" id="teileingabe" name="suche1" value="2"> <label for="teileingabe" />Teil Eingabe</label><br />
  24. </fieldset>
  25. </p>
  26.  
  27. <p>
  28. Suchen nach: <br />
  29. <fieldset>
  30. <input type="radio" id="vorname" name="suche2" value="vorname" checked="checked" /> <label for="vorname">Vorname</label><br />
  31. <input type="radio" id="nachname" name="suche2" value="nachname" /> <label for="nachname">Nachname</label><br />
  32. <input type="radio" id="stadt" name="suche2" value="ort" /> <label for="stadt">Stadt</label><br />
  33. <input type="radio" id="plz" name="suche2" value="plz" /> <label for="plz">Postleitzahl</label><br />
  34. <input type="radio" id="iban" name="suche2" value="iban" /> <label for="iban">IBAN</label><br />
  35. </fieldset>
  36. </p>
  37.  
  38. <br /> <br />
  39. <hr />
  40. <br /> <br />
  41.  
  42. <?php
  43. if($_POST['senden']) {
  44. $link=mysql_connect("localhost","root","") or die("Fehler!");
  45.  
  46. mysql_select_db("formular");
  47.  
  48. if($_POST['suche1'] == 1) {
  49. $query = 'SELECT * FROM personen WHERE ' . $_POST['suche2'] . ' = "' . $_POST['eingabe'] . '"';
  50. } else if($_POST['suche1'] == 2) {
  51. $query = 'SELECT * FROM personen WHERE ' . $_POST['suche2'] . ' LIKE "' . $_POST['eingabe'] . '%"';
  52. } else {
  53. die("<p>Es ist ein Fehler aufgetreten!</p>");
  54. }
  55.  
  56. if (!$res=mysql_query($query)) {
  57. echo "Fehler bei der Abfrage!";
  58. echo mysql_error();
  59. exit;
  60.  
  61. } else {
  62. echo "<table>";
  63. echo "<tr>";
  64.  
  65. for ($j=0; $j<mysql_num_fields($res); $j++) {
  66. echo"<th>".mysql_field_name($res,$j)."</th>";
  67. }
  68.  
  69. echo "</tr>";
  70.  
  71. while ($zeile=mysql_fetch_row($res)) {
  72. echo "<tr>";
  73.  
  74. for ($j=0; $j<mysql_num_fields($res); $j++) {
  75. echo"<td>".$zeile[$j]."</td>";
  76. }
  77.  
  78. echo "</tr>";
  79. };
  80.  
  81. echo "</table>";
  82. }
  83.  
  84. mysql_close($link);
  85. }
  86. ?>
  87. </form>
  88. </body>
  89. </html>
Add Comment
Please, Sign In to add comment