drsw9390405 2018-04-17 12:14
浏览 26
已采纳

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

Hello so I am having a slight problem at the moment Basically I have a while loop that outputs a table called job from database along with a bid button that links to bid.php. When the button takes me to the page I want it to carry over the jobid of the row that the button was clicked so I can enter the specific value into my database does anyone have any ideas on how to move over currently I am trying to do it using POST but I keep getting errors and the variable dosnt seem to be moving over.I just get a blank page and the id is not displayed.

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

Here is bid.php where I am trying to get the specific id of the row from findjob22.php:

<?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条回答 默认 最新

  • donglu3184 2018-04-17 12:27
    关注

    I am not sure you can pass values in the submit button, but you can use a hidden input to pass the value.

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

    If you want it to work like you have it use a button.

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

    if you want to also pass some data:

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

    Then you will have a $_POST["job_id"] and $_POST["bid"] in bid.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败
  • ¥15 Centos7 / PETGEM
  • ¥15 csmar数据进行spss描述性统计分析
  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题