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

p4rjhz4m  于 2021-06-25  发布在  Mysql
关注(0)|答案(1)|浏览(277)

你好,所以我现在有一个小问题,基本上我有一个while循环,它从数据库输出一个名为job的表,还有一个链接到bid.php的bid按钮。当按钮带我到页面时,我希望它带着点击该按钮的行的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>-->
ars1skjm

ars1skjm1#

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

<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>

那你就有机会了 $_POST["job_id"] 以及 $_POST["bid"] 在bid.php中

相关问题