如何使用客户ID生成客户信息?

时间:2019-07-15 12:21:44

标签: php mysql

我有一个输出选项,例如“如果我输入Thomas并进行搜索,它将显示我们公司中的所有Thomas及其特定的ID(OL_ID),全名,城市和地址”,从此输出中,我需要执行此操作接下来的任务。

1)当我单击一个“ Thomas”的“ ID(OL_ID)”时,它将带我到该特定用户的信息。我的所有信息都存储在数据库中。

我已经创建了该表,将其连接到DATABASE并生成了此输出。请有人帮我,当我在port.php中单击他的id(OL_ID)时,如何生成特定的客户信息。我在example.php中遇到一些错误。

当我在port.php中单击Ol_ID时,它应该进入example.php并生成所选OL_ID的特定用户信息

<!DOCTYPE html>
<html lang="de">
<head>
<meta  http-equiv="Content-Type" content="text/html;  charset=iso-8859-1">
<link rel='stylesheet' href='https://use.fontawesome.com/releases/v5.7.0/css/all.css'
      integrity='sha384-lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ'
      crossorigin='anonymous'>
<title>Stammdaten</title>
</head>
<style>
body
{
    background-image: url("background.gif");
    background-position:  center;
}
.nav-stammdaten
{
   width: 100%;
   background-color:rgba(238, 130, 7, 0.9);
   overflow: auto;
   text-shadow: 2px 1px;
}
.nav-stammdaten a
{
   float: left;
   width: 12%;
   height: inherit;
   padding: 12px;
   color: rgb(23, 32, 0 );
   text-decoration: none;
   font-size: 35px;
   text-shadow: 2px 1px;
   text-align: center;
}
.nav-stammdaten a:hover, .active
{
   background-image: url("background.gif");
   color: white;
   webkit-border-top-left-radius: 3278375427275px;
   -webkit-border-bottom-right-radius: 3278375427275px;
   -moz-border-radius-topleft: 3278375427275px;
   -moz-border-radius-bottomright: 3278375427275px;
   border-top-left-radius: 3278375427275px;
   border-bottom-right-radius: 3278375427275px;
}
input[type=text], input[type=date], input[type=number]
{
    background-color: #FFF2E6;
    border-radius: 40px 10px 35px 8px;
    font-weight: 900;
    font-family: "Comic Sans MS", cursive, sans-serif;
    width: 250px;height:30px;
    padding-left: 60px;
}
input[type=text]:hover
{
    box-shadow: 2px 2px;
}
div.sub input[type=submit],  input[type=reset]
{
    border-radius: 40px 10px 35px 8px;
    font-weight: bolder;
    width: 150px;height:50px;
    float: right;
    background-color:rgba(238, 130, 7, 0.9);
    color: rgb(23, 32, 42 );
    text-decoration: none;
    font-size: 23px;
    text-align: center;
    text-shadow: 2px 1px;
}
input[type=submit]
{
    border-radius: 40px 10px 35px 8px;
    font-weight: bolder;
    width: 150px;height:50px;       
    background-color:rgba(238, 130, 7, 0.9);
    color: rgb(23, 32, 42 );
    text-decoration: none;
    font-size: 23px;
    text-shadow: 2px 1px;
    text-align: center;
}
input[type=submit]:hover
{
    background-image: url("background.gif");
    box-shadow: 2px 5px;
    color: white;
    font-size: 30px;
}
div.sub input[type=reset]:hover
{
    background-image: url("background.gif");
    box-shadow: 2px 5px;font-size: 30px;
    color: white;
}
div.sub input[type=submit]:hover
{
    background-image: url("background.gif");
    box-shadow: 2px 3px;font-size: 30px;
    color: white;
} 
div.form1
{
    border-radius:110px;
    width: 800px;
    padding-left:150px;
    position:fixed;
    padding-right: 100px;
    background-color:#E2D4B4;
    border: 3px solid #C5AA6A;
    height: 950px;
    right:890px;
}
input[type=text]
{
   padding-right:135px;
   font-family: "Comic Sans MS", cursive, sans-serif;
} 
input[type=text]:focus,input[type=email]:focus,textarea:focus
{
   outline: 0;
   border-color: #4697e4;
}
div.form1 input[type=text],input[type=email]
{
   width: 70%;
}
input[type=number]
{
   width: 25%;
}
input[type=text],input[type=email],textarea
{
   border-top: 1px solid #ccc;
   border-left: 1px solid #ccc;
   border-right: 1px solid #eee;
   border-bottom: 1px solid #eee;
   color: #4ba34b;
}
form > div
{
   clear: both;
   overflow: hidden;
   padding: 1px;
   margin: 0 0 10px 0;
}
div.anrede option
{
   background-image: url("background.png");
   width: 250px;
   border-radius: 40px 10px 35px 8px;
   font-weight: 900;
   font-family: "Comic Sans MS", cursive, sans-serif;
   width: 150px;height:50px;
   padding-left: 60px;
}
</style>
<body>
<!--Here goes the link back to Index page-->   
<div class="nav-stammdaten">
        <a class="active" href="stammdaten.html"><i class='fa fa-fw fa-database' style='font-size:35px;color:white'></i>Stammdaten</a>
        <a href="portierung.html"><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='color: white;font-weight: bolder;font-family: "Comic Sans MS", cursive, sans-serif'><i>Kunden suche:</i></p>
<form  method="post" action="example.php"  id="searchform">
        <input type="text" name="keyword" placeholder="Enter OL_ID"> 
        <input type="submit" name="submit" value="Suche">
</form>
<form method="post" action="port.php">
<br><br>
<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>

<!--Vorname-->
<div><br>
<label class="desc" id="title1" for="text1">Vorname</label>
  <div>
    <input id="vorname" name="vorname" type="text" class="field text fn" value="" size="8" tabindex="1" placeholder="vorname">
  </div>
</div>

<!--Nachname-->
<div><br><br>
<label class="desc" id="title1" for="text2">Nachname</label>
 <div>
    <input id="nachname" name="nachname" type="text" class="field text fn" value="" size="8" tabindex="1" placeholder="Ihr Nachname">
 </div>
</div>

<!--Email address-->
<div><br>
<label class="desc" id="title1" for="text3">E-mail-Addresse</label>
 <div>
    <input id="email" name="email" type="text" class="field text fn" value="" size="8" tabindex="1" placeholder="Deine Email">
 </div>
</div>

<!--Telefon nummer-->
<div><br>
<label class="desc" id="title1" for="text4">Telefonnummer</label>
 <div>
    <input id="mobil" name="mobil" type="number" class="field text fn" value="" size="8" tabindex="1" placeholder="Deine Telefonnummer">
 </div>
</div>

<!--Geburtstag-->
<div><br><br>
<label class="desc" id="title3" for="text5">Geburtstag</label>
 <div>
    <input id="geburtstag" name="geburtstag" type="date" spellcheck="false" value="" maxlength="255" tabindex="3"> 
 </div>
</div>

<!--Plz-->
<div><br><br>
<label class="desc" id="title3" for="text6">Plz</label>
 <div>
    <input id="plz" name="plz" type="number" spellcheck="false" value="" maxlength="255" tabindex="3" placeholder="Ihre Postleitzahl"> 
 </div><br><br>

<!--Ort-->
<label class="desc" id="title3" for="text7">Ort</label>
 <div>
    <input id="ort" name="ort" type="text" spellcheck="false" value="" maxlength="255" tabindex="3" placeholder="Dein Platz"> 
 </div><br><br>
</div>

<!--Strasse--> 
<div>
<label class="desc" id="title1" for="text8">Stra&szlig;e</label>
 <div>
    <input id="strasse" name="strasse" type="text" class="field text fn" value="" size="8" tabindex="1" placeholder="Deine Stra&szlig;e">
 </div>
</div>

<!--Hausnummer--> 
<div><br><br>
<label class="desc" id="title3" for="text9">Hausnummer</label> 
<input id="hnr" name="hnr" type="number" spellcheck="false" value="" maxlength="255" tabindex="3" placeholder="Ihre Hausnummer">

<!--Hausnummerzusatz-->     
<label class="desc" id="title3" for="text9">Hausnummerzusatz</label>
    <input id="adrZus" name="adrZus" 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>
<br><br><br><br><br><br>
</body>
</html>

PHP code(port.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>
<style>
body
{
     background-image: url("background.gif");
     color:white;
     font-size:40px;
     font-family:"times new roman", times, serif;
}
</style>
<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="example.php"><?php echo $row['OL_ID']; ?></a></td>
       <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();
     }
?>
<html>
<head></head>
</head>
<style>
button[type=button1]
    {
        border-radius: 40px 10px 35px 8px;
        width: 170px;height:60px;
        padding-left: 3px;
        color: white;
        text-shadow: 2px 1px;
        font-size: 28px;
        background-color:rgba(238, 130, 7, 0.9);
        font-weight:bolder;
        }
button[type=button1]:hover
  {
    background-image: url("background.gif");
    cursor: pointer;
    color: white;
    font-size:32px;
    box-shadow:2px 5px;
  }
</style>
<body>
<br/>
<button type="button1" onclick="goBack()"/>Zurück</button>
<script>
function goBack()
                {
                  window.history.back();
                }
</script>
</body>
</html>

Php code (example.php):

<?php
//connect to DB
ini_set('display_errors', 1); //<- here you can switch on and off the error reporting 0 / 1 - makes life easy ;) 
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

//echo $_POST['vorname'];

$debug=1;
            $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);

           if(isset($_POST['submit'])){
                $num=$_POST['OL_ID'];
               $statement = $myconnection->prepare("SELECT * FROM OL_trans  WHERE OL_ID LIKE '$num' ");
               $statement->execute();
               $key = $statement->fetchall();
               foreach($key as $value){ ?>
<!DOCTYPE html>
<html>
<head>
     <title>Data fetched</title>
</head>
<style>
     body{
     background-image: url("background.gif");
     color: white;
     font-weight: bolder;
     font-size: 40px;
     font-family:  sans-serif serif cursive;
     padding-top: 105px;    }
</style>
<body>
               <br/><br/><table align="center" border="3px" style="width:70%; line-height:80px; background-color:#616261">
                    <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><?php echo $value['OL_ID']; ?></a></td>
       <td><?php echo $value['vorname']; ?></td>
       <td><?php echo $value['nachname']; ?></td>
       <td><?php echo $value['email']; ?></td>
       <td><?php echo $value['strasse']; ?></td>
       <td><?php echo $value['ort']; ?></td>
       <td><?php echo $value['plz']; ?></td>
       <td><?php echo $value['telefon']; ?></td>
       <td><?php echo $value['mobil']; ?></td>
  </tr>   
       </table>
</body>  
</html>
<?php
          }
          }
          else{
               echo "enter the corect OL_ID again!";
          }
     }
     catch(PDOException $e)
         {
           echo "Connection failed: " . $e->getMessage();
        }
?>
<html>
    <head></head>
    <style>
        button[type=button1]{
        border-radius: 40px 10px 35px 8px;
        width: 160px;height:55px;
        padding-left: 3px;
        color: white;
        text-shadow: 2px 1px;
        font-size: 28px;
        background-color:rgba(238, 130, 7, 0.9);
        font-weight:bolder;
        }
        button[type=button1]:hover{
       background-image: url("background.gif");
        cursor: pointer;
        color: white;
        font-size:32px;
        box-shadow: 2px 5px;
        }
    </style>
    <body>
     <br/>
  <button type="button1" onclick="goBack()"/>Zurück</button>
  <script>
     function goBack() {window.history.back();}
  </script>
    </body>
</html>

0 个答案:

没有答案