连接到mysql后多个搜索框的php代码

我需要在 PHP 中创建一个搜索表单。我有名字、姓氏、dob、城市和其中的许多字段。当我只输入名字和搜索时,它应该打印我输入的用户的信息。同样,当我输入城市名称并搜索时,它应该输出该城市的所有用户。

这是我的PHP代码:

if(isset($_POST['submit'])){ $num=$_POST['Fielformd1']; $statement = $myconnection->prepare("SELECT * FROM OL_trans WHERE vorname LIKE '$num'"); $statement->execute(); $key = $statement->fetchall(); foreach($key as $value){ echo '
'.$value['vorname']. ' - '.$value['nachname']。' - '.$value['strasse']。' - '.$value['plz']。' - '.$value['ort']。' - '.$value['email']。' - '.$value['电话']。' - '.$value['mobil'].'

'; } } else{ echo"再次输入正确的名称"; } }


牛魔王的故事
浏览 202回答 1
1回答

慕婉清6462132

所以你可以尝试把它改成这样:<form method="post" action="example.php" id="searchform">&nbsp; &nbsp; <input type="text" name="keyword">&nbsp; &nbsp; <input type="submit" name="submit" value="submit"></form>if(isset($_POST['submit'])){&nbsp; &nbsp; $name=$_POST['keyword'];&nbsp; &nbsp; $statement = $myconnection->prepare("SELECT * FROM OL_trans&nbsp; WHERE (ort LIKE '%$name%') OR (plz LIKE '%$name%') OR (vorname LIKE '%$name%')");&nbsp; &nbsp; $statement->execute();&nbsp; &nbsp; $key = $statement->fetchall();&nbsp; &nbsp; foreach($key as $value){&nbsp; &nbsp; &nbsp; &nbsp; echo '<br/>'.$value['vorname'].&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ' - '.$value['nachname'].&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ' - '.$value['strasse'].&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ' - '.$value['plz'].&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ' - '.$value['ort'].&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ' - '.$value['email'].&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ' - '.$value['telefon'].&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ' - '.$value['mobil'].'<br/><br/>';&nbsp; &nbsp; }}else{&nbsp; &nbsp; echo"enter correct name again";}
打开App,查看更多内容
随时随地看视频慕课网APP