2015-09-30 31 views
0

這是search.php代碼:(這一部分,我將搜索關鍵字,然後顯示到retrievecustomerinfo.php檢索信息並在另一個頁面選擇信息彈出

<?php 
$strKeyword = NULL; 
?> 

<body> 
<div align="center"> 
<form name="frmSearch" method="post" action="retrievecustomerinfo.php"> 
    <table > 
     <tr> 
      <th>Keyword 
       <input name="txtKeyword" type="text" id="txtKeyword" value="<?php echo $strKeyword; ?>"> 
       <input type="submit" value="Search"> 
      </th> 

     </tr> 
    </table> 
    <br> 
</form> 
</div> 
</body> 

這是retrievecustomerinfo.php代碼:(此頁面會顯示結果哪些用戶需要的信息)

<?php 
ini_set('display_errors', 1); 
error_reporting(~0); 

$strKeyword = NULL; 

if (isset($_POST["txtKeyword"])) { 
    $strKeyword = $_POST["txtKeyword"]; 
} 
$sql = "SELECT * FROM customer_info WHERE cust_ic LIKE '%" . $strKeyword . "%' OR cust_hp_contact1 LIKE '%" . $strKeyword ."%' OR cust_name LIKE '%" . $strKeyword . "%' limit {$start} , {$perpage}"; 

$query = mysqli_query($conn, $sql); 
?> 
<form name="retrieve" action="topuppage.php" method="post"> 
<table class="table table-hover" > 
    <thead> 
     <tr> 
      <th>Number</th> 
      <th>Name</th> 
      <th>State</th> 
      <th>Contact Number</th> 
      <th>Action</th> 
     </tr> 
    </thead> 

    <?php 
    $no = 1; 
    while ($result = mysqli_fetch_array($query, MYSQLI_ASSOC)) { 
     ?> 
     <tr> 
      <td><?php echo $no ?></td> 
      <td><?php echo $result['cust_name'] ?></td> 
      <td><?php echo $result['cust_state'] ?></td> 
      <td><?php echo $result['cust_hp_contact1'] ?> 
       <?php echo $result['cust_hp_contact2'] ?></td> 
      <td> 
       <button type="submit" name="cust_name" value="<?php echo $result['cust_name'] ;?>" 
         name="cust_hp_contact1" value="<?php echo $result['cust_hp_contact1'] ;?>" class="btn btn-link">SELECT</button> 
      </td> 
     </tr> 
     <?php 
     $no++; 
    } 
    ?> 
</table> 
<?php 
mysqli_close($conn); 
?> 

這是topuppage代碼:(即用戶在retrievecustomerinfo.php選擇此頁面將顯示值)

<form name="getdata" method="get"> 
<div> 

    <h5>TAG THIS SALE ORDER TO THE FOLLOWING CUSTOMER</h5> 
    <div class="col-xs-3"> 
     <label for="cname">Contact Name</label> 
     <input type="text" class="form-control input-sm" id="cname" 
       value=" 
        <?php 
        if(isset($_POST['cust_name'])) 
         { 
         echo $_POST['cust_name']; 

         } 
         ?> "> 



     <label for="cno">Contact Number</label> 
     <input type="text" class="form-control input-sm" id="cno" 
       value=" 
        <?php 
        if(isset($_POST['cust_hp_contact1'])) 
         { 
         echo $_POST['cust_hp_contact1']; 

         } 
         ?> "> 
     <p></p> 
     <button type="reset" class="btn btn-default">Clear</button> 
    </div> 

</div> 
</form> 

如何從retrievecustomerinfo.php獲得價值併發布到topuppage.php的文本框中應該是聯繫人姓名和聯繫電話號碼?

回答

0

在您的代碼中更改retrievecustomerinfo.php中的這一行:我在cust_name之前添加單選按鈕。這樣當用戶提交我們topuppage.php得到崗位價值

<td><input type="radio" name="cust_name" value="<?php echo $result['cust_name'] ?>" /><?php echo $result['cust_name'] ?></td> 

在topuppage.php更改此行(其中我已經改變了這個value="<?php if(isset($_POST['cust_name'])) { echo $_POST['cust_name']; } ?>"

<input type="text" class="form-control input-sm" id="cname" value="<?php if(isset($_POST['cust_name'])) { echo $_POST['cust_name']; } ?>"> 

同樣做聯繫號碼。

+0

這個輸出我點擊我得到這樣的結果: i.gyazo.com/455468f3b83bee81d5c2766d711c72b2.png –

+0

您是否添加了這一行:」/>'radio按鈕應該有元素名稱'name =「cust_name」'AND,並提交表格 – Ruprit

+0

是的,結果是可以在文本框中彈出,但在檢索數據之前出錯。 –

0

retrievecustomerinfo.php只值和名稱屬性添加到提交按鈕:

while ($result = mysqli_fetch_array($query, MYSQLI_ASSOC)) { 
    ?> 
    <tr> 
     <td><?php echo $no ?></td> 
     <td><?php echo $result['cust_name'] ?></td> 
     <td><?php echo $result['cust_state'] ?></td> 
     <td><?php echo $result['cust_hp_contact1'] ?> 
      <?php echo $result['cust_hp_contact2'] ?></td> 
     <td> 
      <button type="submit" name="cust_name" value="<?php echo $result['cust_name'] ?>" class="btn btn-link">SELECT</button> 
     </td> 
    </tr> 
    <?php 
    $no++; 
} 

並獲得topuppage.php的$ _ POST值:

<input type="text" class="form-control input-sm" id="cname" value="<?php echo $_POST['cust_name']; ?>"> 
+0

這個輸出我點擊我得到這個結果:https://i.gyazo.com/455468f3b83bee81d5c2766d711c72b2.png –