gpt4 book ai didi

php - 我的内爆问题是什么?

转载 作者:行者123 更新时间:2023-11-27 23:29:21 25 4
gpt4 key购买 nike

我想创建一个表单,用户可以根据他们的输入和选择搜索某些信息。在所有填写数据的表单将使用表格显示之后。我的内爆出现错误,它给了我警告 implode(): Invalid第 111 行传递的参数是

$check = implode("','", $_POST['check_list']);

然后我尝试在它给我的复选框上勾选两个值 mysql_fetch_array() 期望参数 1 是资源,第 125 行中给出的 bool 值是

while($row = mysql_fetch_array($sql)) {

.

      <form method="post">
<div class="form-group">
<h3><label for="usr">Carian bajet anda:</label></h3>
<div class= "col-md-12">
<div class=" col-md-4"></div>

<div class=" col-md-4">
<input name="bajet" type="text" class="form-control" id="usr"></div>

</div>
<div class=" col-md-4"></div>
</div><br>

<h3><label for="sel1">Pilih negeri pilihan anda:</label></h3>

<div class= "col-md-12">
<div class=" col-md-4"></div>

<div class=" col-md-4">
<select class="form-control" name="sel">
<option>Kuala Lumpur</option>
<option>Negeri Sembilan</option>
<option>Pahang</option>
<option>Perak</option>
<option>Terengganu</option>
<option>Selangor</option>

</select>
</div>

<div class=" col-md-4"></div>
</div><br>


<br>
<h5><label for="check">Senarai Pra-perkahwinan:</label></h5>
<center> <div class="checkbox">
<label class="checkbox-inline"> <input type="checkbox"name="check_list[]" value="Jurufoto"><label>Jurufoto</label></label>
<label class="checkbox-inline"> <input type="checkbox"name="check_list[]" value="Butik"><label>Butik</label></label>
<label class="checkbox-inline"> <input type="checkbox"name="check_list[]" value="Hiburan"><label>Hiburan</label></label>
<label class="checkbox-inline"> <input type="checkbox"name="check_list[]" value="Kad Kahwin"><label>Kad Kahwin</label></label>
<label class="checkbox-inline"> <input type="checkbox"name="check_list[]" value="Katering"><label>Katering</label></label>
<br>


</center>
<div class="col-md-4"></div>

<div class="col-md-4">
<button class="btn btn-success btn-sm" name="search">Search&nbsp;<span class="glyphicon glyphicon-search"></span></button><br><br>
</div>

<div class="col-md-4"></div>
</div>


</form>
<table class="table table-bordered">
<thead>
<tr>

<th>Jenis</th>
<th>Vendor</th>
<th>Negeri</th>
<th>No.</th>
<th>Pakej</th>
<th>Harga</th>
<th></th>
</tr>
</thead>
<tbody>
<?php
$check = array();
$budget = $_POST['bajet'];
$select = $_POST['sel'];
$check = implode("','", $_POST['check_list']);
$finalCheck = "'".$check."'";
$check = array();

if (isset($_POST['search'])) {
mysql_select_db($database_conn, $conn);

$sql = mysql_query(" SELECT *
FROM vendor
RIGHT JOIN item
ON vendor.v_id=item.v_id
WHERE item.harga <= '%". $budget . "%'
AND vendor.state = '%". $select ."%'
AND vendor.type IN ('%". $finalCheck ." %')" );
while($row = mysql_fetch_array($sql)) {
?>
<tr>

<td><?php echo $row['type'] ?></td>
<td><?php echo $row['companyName'] ?></td>
<td><?php echo $row['state'] ?></td>
<td><?php echo $row['contact'] ?></td>
<td><?php echo $row['harga'] ?></td>
<td><?php echo $row['pakej'] ?></td>
<td><a href="index.php?v_id=<?php echo $row['v_id']?>">View Package</a></td>


</tr>

<?php }
}
print_r($_POST['check_list'] );
?>

</tbody>
</table>
</div>

最佳答案

总是通过打印值来调试你的代码,并检查它是否有所需的输出

取笑一下,你的 check_list 的 post 值是

$_POST['check_list'] = ['Jurufoto','Hiburan'];

所以根据你的代码像这样内爆之后

$check = implode("','", $_POST['check_list']);

$finalCheck = "'".$check."'";

您的 $finalCheck 字符串将像这样 "'Jurufoto','Hiburan'"

当你将它与这样的查询连接起来时

AND vendor.type IN ('%". $finalCheck ." %')" );

变成这样

 AND vendor.type IN ('%'Jurufoto','Hiburan' %')" );

哪个是错误的sql语句,你必须这样改

 AND vendor.type IN (". $finalCheck .")" );

或者如果你想检查一下,那么你必须看到这个线程

MySQL IN with LIKE

并确保在获取数据之前打印$sql并将其与您想要的输出相匹配

现在你的代码将是这样的

<form method="post">
<div class="form-group">
<h3><label for="usr">Carian bajet anda:</label></h3>
<div class="col-md-12">
<div class=" col-md-4"></div>

<div class=" col-md-4">
<input name="bajet" type="text" class="form-control" id="usr">
</div>

</div>
<div class=" col-md-4"></div>
</div>
<br>

<h3><label for="sel1">Pilih negeri pilihan anda:</label></h3>

<div class="col-md-12">
<div class=" col-md-4"></div>
<div class=" col-md-4">
<select class="form-control" name="sel">
<option>Kuala Lumpur</option>
<option>Negeri Sembilan</option>
<option>Pahang</option>
<option>Perak</option>
<option>Terengganu</option>
<option>Selangor</option>

</select>
</div>

<div class=" col-md-4"></div>
</div>
<br>


<br>
<h5><label for="check">Senarai Pra-perkahwinan:</label></h5>
<center>
<div class="checkbox">
<label class="checkbox-inline"> <input type="checkbox" name="check_list[]"
value="Jurufoto"><label>Jurufoto</label></label>
<label class="checkbox-inline"> <input type="checkbox" name="check_list[]"
value="Butik"><label>Butik</label></label>
<label class="checkbox-inline"> <input type="checkbox" name="check_list[]"
value="Hiburan"><label>Hiburan</label></label>
<label class="checkbox-inline"> <input type="checkbox" name="check_list[]" value="Kad Kahwin"><label>Kad
Kahwin</label></label>
<label class="checkbox-inline"> <input type="checkbox" name="check_list[]"
value="Katering"><label>Katering</label></label>
<br>
</div>
</center>
<div class="col-md-4"></div>

<div class="col-md-4">
<button class="btn btn-success btn-sm" name="search">Search&nbsp;<span
class="glyphicon glyphicon-search"></span></button>
<br><br>
</div>

<div class="col-md-4"></div>

</form>
<table class="table table-bordered">
<thead>
<tr>
<th>Jenis</th>
<th>Vendor</th>
<th>Negeri</th>
<th>No.</th>
<th>Pakej</th>
<th>Harga</th>
<th></th>
</tr>
</thead>
<tbody>
<?php
if (isset($_POST['search'])) {
$check = array();
$budget = $_POST['bajet'];
$select = $_POST['sel'];
$check = implode("','", $_POST['check_list']);
$finalCheck = "'" . $check . "'";
$check = array();

mysql_select_db($database_conn, $conn);

$sql = mysql_query(" SELECT *
FROM vendor
RIGHT JOIN item
ON vendor.v_id=item.v_id
WHERE item.harga <= '%" . $budget . "%'
AND vendor.state = '%" . $select . "%'
AND vendor.type IN (" . $finalCheck . ")");
while ($row = mysql_fetch_array($sql)) {
?>
<tr>

<td><?php echo $row['type'] ?></td>
<td><?php echo $row['companyName'] ?></td>
<td><?php echo $row['state'] ?></td>
<td><?php echo $row['contact'] ?></td>
<td><?php echo $row['harga'] ?></td>
<td><?php echo $row['pakej'] ?></td>
<td><a href="index.php?v_id=<?php echo $row['v_id'] ?>">View Package</a></td>


</tr>

<?php }
}
?>

</tbody>
</table>

不要使用 mysql 连接,因为 mysql_* 函数已从 5.5.0 开始弃用。使用 mysqliPDO 进行数据库连接。

关于php - 我的内爆问题是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36708985/

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