php - 在其中搜索客户后如何填写搜索表单?

标签 php mysql

我已经为客户创建了一个搜索表单。当我输入一个客户姓名(在 portierung.html 中)时,它会打印他/她的信息(在 port.php 中)。我为所有客户都有一个唯一的 OL_ID。当我单击 OL_ID(在 port.php 中)时,它应该填写 portierung.html 中客户的所有字段。

我已经开发了 port.php,它用 OL_ID 打印客户信息。现在,我如何填写 portierung.html 中的所有字段?点击一位客户的 OL_ID 后?任何线索将不胜感激

Portierung.html:

 <!DOCTYPE html>
    <html lang="en">

    <body>
     <!-- Start von nav_bar-->
    <div class="navbar_port">
      <a href="stammdaten.html"><i class='fa fa-fw fa-database' style='font-size:35px;color:white'></i> Stammdaten</a>
      <a class="active" href="#"><i class='fa fa-fw fa-plug' style='font-size:35px;color:white'></i> Portierung</a> 
      <a href="#"><i class='fa fa-fw fa-phone' style='font-size:35px;color:white'></i> Telefon</a> 
      <a href="#"><i class="fa fa-fw fa-wifi" style='font-size:35px;color:white'></i> Internet</a>
      <a href="#"><i class="fa fa-fw fa-cloud" style='font-size:35px;color:white'></i> Zus&#228;tzliche Daten</a>
      <a href="#"><i class="fa fa-fw fa-spinner" style='font-size:35px;color:white'></i> Tab - 1</a>
      <a href="#"><i class="fa fa-fw fa-spinner" style='font-size:35px;color:white'></i> Tab - 2</a>
    </div>

    <p style='font-family: "Comic Sans MS", cursive, sans-serif;color: white;font-weight: bolder'><i>Kunden suche:</i></p>
    <form  method="post" action="example.php"  id="searchform">
            <input type="number" placeholder="Enter the OL_ID" name="keyword">  
            <input type="submit" name="submit" value="Suche">
    </form>


    <form action="port.php" method="post">

    <br><br>
        <!--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="vorname" name="vorname" 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="nachname" name="nachname" 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="email" name="email" type="text" class="field text fn" value="" size="8" tabindex="1" placeholder="Deine Emailadresse"></div>
    </div>
    <div><br>
        <label class="desc" id="title1" for="Field1">Telefonnummer</label>
        <div><input id="telefon" name="telefon" 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="geburtstag" name="geburtstag" 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="plz" name="plz" 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="ort" name="ort" 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="strasse" name="strasse" 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>
        <div><input id="hnr" name="hnr" type="number" spellcheck="false" value="" maxlength="255" tabindex="3" placeholder="Ihre Hausnummer"></div></div><br><br>
         <div>
          <label class="desc" id="title3" for="Field3">Hausnummerzusatz</label>
          <div><input id="adrZus" name="adrZus" type="number" spellcheck="false" value="" maxlength="255" tabindex="3" placeholder="Zus&#228;tzliche Adresse"></div></div>
    <div class="sub"><br>
        <br>
         <input type="submit" name="submit" value="Suche">
          <input type="reset" name="reset" value="Reset">
    </div>
      </div>
    </form>
    <br><br>
    </body>
    </html>

端口.php:

<?php
session_start();
//connect to DB
ini_set('display_errors', 0); //<- here you can switch on and off the error reporting 0 / 1     
ini_set('display_startup_errors', 1); 
error_reporting(E_ALL);
$host = "localhost"; $username = "root"; $password = "mysqlr00tpa55";
try
     { 
      $myconnection = new PDO("mysql:host=$host;dbname=myDB", $username, $password);
      // set the PDO error mode to exception    
      $myconnection ->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
      //ECHO "TEST";
if(isset($_POST['submit']))
{
    $sql = 'SELECT * FROM OL_trans WHERE';
    if (!empty($_POST['vorname']))
    //Vorname
    {
        $sql .= ' vorname = ? AND ';
        $params[] =  $_POST['vorname'];
    }   
    if (!empty($_POST['nachname']))
    //Nachname
    {
        $sql .= ' nachname = ? AND ';
        $params[] =  $_POST['nachname'];
    }
    if (!empty($_POST['email']))
    //E-mail address
    {
        $sql .= ' email = ? AND ';
        $params[] =  $_POST['email'];
    }
    if (!empty($_POST['strasse']))
    //Strasse
    {
        $sql .= ' strasse = ? AND ';
        $params[] =  $_POST['strasse'];
    }
    if ( !empty($_POST['ort']) )
    //Ort
    {
        $sql .= ' ort= ? AND ';
        $params[] =  $_POST['ort'];
    }
    if ( !empty($_POST['plz']))
    //Plz
    {
        $sql .= ' plz= ? AND ';
        $params[] = $_POST['plz'];
    }
    if ( !empty($_POST['telefon']))
    //Telefonnummer
    {
        $sql .= ' telefon=? AND ';
        $params[] = $_POST['telefon'];
    }
    if( !empty($_POST['adrZus']))
    //HausnummerZusatz
    {
        $sql .= ' adrZus=? AND ';
        $params[] = $_POST['adrZus'];
    }
    if( !empty($_POST['hnr']))
    //Hausnummer
    {
        $sql .= ' hnr=? AND ';
        $params[] = $_POST['hnr'];
    }
     $sql = rtrim($sql, 'AND ');
     $stmt = $myconnection->prepare($sql);
     $stmt->execute($params);
     $rows = $stmt->fetchAll();
     foreach($rows as $row)
     {
          ?>
<!DOCTYPE html>
<html>
<head>
<title>Data fetched</title>
</head>
 <body>
<br/><br/><table align="center" border="3px" style="width:75%; line-height:40px; background-color:#616263">
                    <t>
                         <th style="color:rgba(238, 130, 7, 0.9); font-size:25px">Customer id</th>
                         <th style="color:rgba(238, 130, 7, 0.9); font-size:25px">Vorname</th>
                         <th style="color:rgba(238, 130, 7, 0.9); font-size:25px">Nachname</th>
                         <th style="color:rgba(238, 130, 7, 0.9); font-size:25px">Email Id</th>
                         <th style="color:rgba(238, 130, 7, 0.9); font-size:25px">Strasse</th>
                         <th style="color:rgba(238, 130, 7, 0.9); font-size:25px">Ort</th>
                         <th style="color:rgba(238, 130, 7, 0.9); font-size:25px">Plz</th>
                         <th style="color:rgba(238, 130, 7, 0.9); font-size:25px">Telefon</th>
                         <th style="color:rgba(238, 130, 7, 0.9); font-size:25px">Mobil</th>
                    </t>
<tr align="center">                  
       <td style="cursor: pointer;">

        <a href="portierung.html?id=<?php echo $row['OL_ID']; ?>"><?php echo $row['OL_ID']; ?></a>
       <td><?php echo $row['vorname'];?></td>
       <td><?php echo $row['nachname'];?></td>
       <td><?php echo $row['email'];?></td>
       <td><?php echo $row['strasse'];?></td>
       <td><?php echo $row['ort'];?></td>
       <td><?php echo $row['plz'];?></td>
       <td><?php echo $row['mobil'];?></td>
</tr>   
</table>
</body>  
</html>
<?php
} 
}else
{
     echo"Enter the correct information again!";
}
 }
catch(PDOException $e)
   {
     echo "Connection failed: " . $e->getMessage();
     }
?>

我不知道如何将 OL_ID 链接从 port.php 连接到 portierung.html 并填充表的所有字段。非常感谢任何帮助!提前非常感谢

最佳答案

看起来您有一个 php 页面(您可以在其中使用 PHP 进行编程、访问数据库等),并且您有一个静态 HTML 页面 (Portierung.html)。

如果我理解正确的话,您希望 HTML 页面基于唯一标识符 (OL_ID) 显示信息。对吗?

如果是这样:HTML 是相当静态的,除非您想开始使用带有 XHR 请求的 javascript。最简单的方法可能是将 HTML 更改为 PHP 页面,接收 OL_ID(例如在 url 中),然后从数据库中获取信息。

https://www.yoursite.de/Portierung.php?OL_ID=1234567

在 Portierung.php 中,您可以使用以下方式获取值:

$OL_ID = $_GET['OL_ID'];

然后获取信息,就像在 Port.php 中所做的那样

谨防人们更改网址中的 OL_ID。我不知道你的用例,但这可能是一个安全漏洞。 (例如,我在 URL 中输入另一个 OL_ID 来获取我不应该看到的信息。)

关于php - 在其中搜索客户后如何填写搜索表单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57042952/

相关文章:

mysql - mysql 如何处理两个相等的索引?

php - 类型错误 : Cannot create property 'lastUpdateCheck' on string 'lastUpdateCheck 1599160669280'

php - 显示 mysql 数据库的结果

php - 根据之前的日期选择日期范围

php - 如何在 .js 文件中使用 php 数组值?

php - 修改并重做 codeigniter 中的最后一个查询

php - 使用查询作为数组插入多个值

php - PHP中如何检测文件是否由用户上传?

MySQL 允许从特定域访问?

mysql - 搜索条目 - 在数据库中(不指定列名称/表名称)