gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 17:44:06 24 4
gpt4 key购买 nike

你好,我现在遇到了一个小问题基本上我有一个 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>-->

最佳答案

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

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

关于PHP 将变量移动到另一个文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49877860/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com