PHP中的多输入掩蔽

时间:2019-05-09 09:45:41

标签: php mysql sql

我需要在PHP中创建一个搜索表单。我有一个名字,姓氏,出生日期,城市以及其中的许多字段。当我仅输入名字并搜索时,它应该打印我输入的用户的信息。同样,当我输入城市名称并进行搜索时,它应该输出城市中的所有用户。

PHP代码:

if(isset($_POST['submit']) ){


 $keyword=$_POST['text'];


$statement = $myconnection->prepare("SELECT * FROM OL_trans  WHERE vorname LIKE '$keyword'");
           $statement->execute();
           $key = $statement->fetchall();
           foreach($key as $value){
               echo '<br/>'.$value['vorname'].
               ' - '.$value['nachname'].
               ' - '.$value['strasse'].
               ' - '.$value['plz'].
               ' - '.$value['ort'].
               ' - '.$value['email'].
               ' - '.$value['telefon'].
               ' - '.$value['mobil'].'<br/><br/>'; 
           } 
      }
      else{
           echo"enter correct name again";
      }
      }
 catch(PDOException $e)
     {
       echo "Connection failed: " . $e->getMessage();
    }

HTML代码:

    <form method="post" action="form.php">
    <!--Beginn des Anrede-->
    <div class="form1"><br><br>
    <div class="names">
        <div class="anrede"> 
    <label for="Anrede">Anrede
        <select id="select" name="anrede" >
        <option value="">--Please choose an option--</option>
        <option value="herr">Herr</option>
        <option value="frau">Frau</option>
        <option value="andere">Andere</option>
        </select>
        </label></div>
        <br><br>
      <div><br>
        <label class="desc" id="title1" for="Field1">Vorname</label>
        <div>
        <input id="text1" name="text[]" type="text" class="field text fn" value="" size="8" tabindex="1" placeholder="Ihr Vorname">
        </div>
      </div>
        <div><br><br>
        <label class="desc" id="title1" for="Field1">Nachname</label>
        <div>
      <input id="text2" name="text[]" type="text" class="field text fn" value="" size="8" tabindex="1" placeholder="Ihr Nachname">
    </div>
  </div>
<div><br>
        <label class="desc" id="title1" for="Field1">E-mail-Addresse</label>
        <div>
          <input id="text3" name="text[]" type="text" class="field text fn" value="" size="8" tabindex="1" placeholder="Deine Email">
        </div>
      </div>
      <div><br>
        <label class="desc" id="title1" for="Field1">Telefonnummer</label>
    <div>
      <input id="text4" name="text[]" type="number" class="field text fn" value="" size="8" tabindex="1" placeholder="Deine Telefonnummer">
    </div>
    </div>
    <div><br><br>
        <label class="desc" id="title3" for="Field3">
          Geburtstag
        </label>
        <div>
          <input id="text5" name="text[]" type="date" spellcheck="false" value="" maxlength="255" tabindex="3"> 
       </div>
      </div>
    <div><br><br>
        <label class="desc" id="title3" for="Field3">
          Plz
        </label>
        <div>
          <input id="text6" name="text[]" type="number" spellcheck="false" value="" maxlength="255" tabindex="3" placeholder="Ihre Postleitzahl"> 
       </div><br><br>
    <label class="desc" id="title3" for="Field3">
          Ort
        </label>
        <div>
          <input id="text7" name="text[]" type="text" spellcheck="false" value="" maxlength="255" tabindex="3" placeholder="Dein Platz"> 
       </div><br><br>
      </div>

     <div>
        <label class="desc" id="title1" for="Field1">Stra&beta;e</label>
        <div>
          <input id="text8" name="text[]" type="text" class="field text fn" value="" size="8" tabindex="1" placeholder="Deine Stra&beta;e">
        </div>
      </div>

     <div><br><br>
        <label class="desc" id="title3" for="Field3">
          Hausnummer
        </label>

          <input id="text9" name="text[]" type="number" spellcheck="false" value="" maxlength="255" tabindex="3" placeholder="Ihre Hausnummer">

          <label class="desc" id="title3" for="Field3">
          Hausnummerzusatz
        </label>
          <input id="text10" name="text[]" type="number" spellcheck="false" value="" maxlength="255" tabindex="3" placeholder="Zus&#228;tzliche Adresse">
          <div><br><br>
          <div class="sub">
          <input type="submit" name="submit" value="Suche">
          <input type="reset" name="reset" value="Reset">
          </div>
        <br><br><br></div>
        </div>
      </div>
    </form>

0 个答案:

没有答案