Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(0);
- $servername = "localhost";
- $username = "root";
- $password = "";
- $datenbank = "formular";
- $suche1 = 1;
- $suche2 = "vorname";
- ?>
- <html>
- <head>
- <title>Datenbank-Abfrage</title>
- </head>
- <body>
- <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
- <p>Suche: <input type="text" name="eingabe" style="width: 300px;" /> <input type="submit" name="senden" value="Senden" /></p>
- <p>
- <fieldset>
- <input type="radio" id="volleeingabe" name="suche1" value="1" checked="checked" /> <label for="volleeingabe">Volle Eingabe</label><br />
- <input type="radio" id="teileingabe" name="suche1" value="2"> <label for="teileingabe" />Teil Eingabe</label><br />
- </fieldset>
- </p>
- <p>
- Suchen nach: <br />
- <fieldset>
- <input type="radio" id="vorname" name="suche2" value="vorname" checked="checked" /> <label for="vorname">Vorname</label><br />
- <input type="radio" id="nachname" name="suche2" value="nachname" /> <label for="nachname">Nachname</label><br />
- <input type="radio" id="stadt" name="suche2" value="ort" /> <label for="stadt">Stadt</label><br />
- <input type="radio" id="plz" name="suche2" value="plz" /> <label for="plz">Postleitzahl</label><br />
- <input type="radio" id="iban" name="suche2" value="iban" /> <label for="iban">IBAN</label><br />
- </fieldset>
- </p>
- <br /> <br />
- <hr />
- <br /> <br />
- <?php
- if($_POST['senden']) {
- $link=mysql_connect("localhost","root","") or die("Fehler!");
- mysql_select_db("formular");
- if($_POST['suche1'] == 1) {
- $query = 'SELECT * FROM personen WHERE ' . $_POST['suche2'] . ' = "' . $_POST['eingabe'] . '"';
- } else if($_POST['suche1'] == 2) {
- $query = 'SELECT * FROM personen WHERE ' . $_POST['suche2'] . ' LIKE "' . $_POST['eingabe'] . '%"';
- } else {
- die("<p>Es ist ein Fehler aufgetreten!</p>");
- }
- if (!$res=mysql_query($query)) {
- echo "Fehler bei der Abfrage!";
- echo mysql_error();
- exit;
- } else {
- echo "<table>";
- echo "<tr>";
- for ($j=0; $j<mysql_num_fields($res); $j++) {
- echo"<th>".mysql_field_name($res,$j)."</th>";
- }
- echo "</tr>";
- while ($zeile=mysql_fetch_row($res)) {
- echo "<tr>";
- for ($j=0; $j<mysql_num_fields($res); $j++) {
- echo"<td>".$zeile[$j]."</td>";
- }
- echo "</tr>";
- };
- echo "</table>";
- }
- mysql_close($link);
- }
- ?>
- </form>
- </body>
- </html>
Add Comment
Please, Sign In to add comment