检索信息并在另一页中选择弹出信息

时间:2015-09-30 11:39:59

标签: php

这是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的文本框中应该是联系人姓名和联系电话?

2 个答案:

答案 0 :(得分:0)

在你的代码中更改retrievecustomerinfo.php中的这一行:我在cust_name之前添加单选按钮。因此,当用户提交时,我们将获得topuppage.php中的post值

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

AND

在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']; } ?>">

同样适用于联系电话。

答案 1 :(得分: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']; ?>">