PHP将变量移动到另一个文档

时间:2018-04-17 12:14:59

标签: php mysql

您好我现在遇到一个小问题基本上我有一个while循环,它输出一个名为job的数据库,以及一个链接到bid.php的出价按钮。当按钮将我带到页面时,我希望它继续执行按钮被单击的行的jobid,这样我就可以将特定值输入到我的数据库中是否有人对如何移动目前的任何想法我正在尝试做它使用POST,但我不断收到错误,变量dosnt似乎正在移动。我只是得到一个空白页面并且不显示id。

这是findjob22.php:

<?php
require 'config.php';
if(isset($_POST['submit']))
{
    $valueToSearch = $_POST['valueToSearch'];
    // search in all table columns
    // using concat mysql function
    $query = "SELECT * FROM `job` WHERE CONCAT(`job_id`,`location`, `description`, `budget`, `duedate`,`title`) LIKE '%".$valueToSearch."%'";
    $search_result = filterTable($query);

}
 else {
    $query = "SELECT * FROM `job`";
    $search_result = filterTable($query);
}

// function to connect and execute the query
function filterTable($query)
{
    $conn = mysqli_connect("localhost", "root", "", "bid4myjob");
    $filter_Result = mysqli_query($conn, $query);
    return $filter_Result;
}

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


        <!-- PAGE CONTENT -->
        <div class="page-content page-search-result">
            <div class="container">
                <!-- Search Form -->
                <form class="form form-horizontal" action="bid.php" method="post">
                    <div class="input-group input-group-lg">
                        <div class="input-group-btn">
                            <!--<select id="search-type-select" name="valueToSearch" class="multiselect multiselect-single-lg search-type-select">
                                <option value="all" selected="selected">All</option>
                                <option value="page">Page</option>
                                <option value="task">Task</option>
                                <option value="user">User</option>
                                <option value="image">Image</option>
                            </select>
                        </div>-->
                        <input class="form-control input-lg" type="text" name="valueToSearch" placeholder="type keyword ..." />
                        <span class="input-group-btn">
                        <button type="submit" name= "submit" value="Search" class="btn btn-primary btn-lg"><i class="icon ion-android-search"></i> Go</button>
                    </span>
                    </div>

                </form>
                <!-- End Search Form -->

            </div>
        </div>
        <div>
            <table>
                <tr>
                    <th>id</th>
                    <th>Title</th>
                    <th>Location</th>
                    <th>Description</th>
                    <th>Budget</th>
                    <th>Due date</th>
                </tr>

      <!-- populate table from mysql database -->
                <?php while($row = mysqli_fetch_array($search_result)):?>
                <tr>
                <?php //$jid= $row['job_id']; ?>

                    <td><?php echo $row['job_id']; ?></td>
                    <td><?php echo $row['title'];?></td>
                    <td><?php echo $row['location'];?></td>
                    <td><?php echo $row['description'];?></td>
                    <td><?php echo $row['price'];?></td>
                    <td><?php echo $row['duedate'];?></td>
                    <td><form method="post" action="bid.php" class="form-horizontal">
                        <?php //echo _("Enter ") . ' ' . $last_bid_plus . ' ' . _('or more'); ?>

                        <!--<div class="input-group ">

                        <input type="number" value="bid" class="form-control" name="bid" id= "bid" required/>
                        </div>
                        <br/>-->
                        <input type="submit" name="job_id"   value="<?php $row['job_id']; ?>"
                               class="btn btn-xlarge btn-block btn-primary">bid</input>
                        <br/>
                    </form></td>
                </tr>
                <?php endwhile;?>
            </table>
        </div>
        <!-- END PAGE CONTENT -->


</body>

</html>

这是bid.php,我试图从findjob22.php获取该行的特定ID:

<?php
// include "job.php" 
$jobid    = $_POST['job_id'];
echo "$jobid"
 ?>
<!--<html>
<div class="col-xs-8">

<div class="page-header white-content">
    <h1><?= _('Your Bid') ?>.</h1>
</div>

<div class="white-content">
    <div class="well">

            <br/><br/>
            <form method="post" action="/listings/bid/<?//=$listingID; ?>/confirm" class="form-horizontal">
                <input type="hidden" value="<?=//$bid_amount?>" class="input-medium" name="bid_amount"/>
                <input type="submit" name="sb_bid" value="<?php// echo _('I agree and I confirm my BID'); ?>" class="btn btn-medium btn-green" />
            </form>

    </div>

</div>

</div>

</html>-->

1 个答案:

答案 0 :(得分:0)

我不确定您是否可以在提交按钮中传递值,但您可以使用隐藏的输入来传递值。

<input type="hidden" value="<?php echo $row['job_id']; ?>" name="job_id" />
<input type="submit" class="btn btn-xlarge btn-block btn-primary">bid</input>

如果你希望它像你一样工作,请使用按钮。

<button type="submit" 
        name="job_id" 
        value="<?php echo $row['job_id']; ?>"
        class="btn btn-xlarge btn-block btn-primary">
    bid
</button>

如果你想传递一些数据:

<form method="post" 
      action="bid.php" 
      class="form-horizontal">
    <div class="input-group">
        <input type="text"  
               class="form-control" 
               name="bid" 
               id="bid" required />
    </div>
    <button type="submit" 
            name="job_id" 
            value="<?php echo $row['job_id']; ?>"
            class="btn btn-xlarge btn-block btn-primary">
        bid
    </button>
    <br/>
</form>

然后,您将在bid.php中找到$_POST["job_id"]$_POST["bid"]