我在这段代码上遇到了麻烦,并且似乎无法解决问题。
我在网上查看过,当前遇到的错误与失败的查询有关,但当我按照步骤解决此问题时,它似乎确实有效。
我需要做的是有两个单独的列,一列用于 id,另一列用于 id 所保存的数据,我需要它从名为 的表中提取信息业务类型表
这是我的代码:
<tr>
<td>Type of Business:</td>
<td>
<select name="typeofbusiness">
<option value=''> - select type of business -</option>
<?php
$sql = "SELECT tbl_typesofbusiness.ID, tbl_typesofbusiness.Agent
FROM tbl_typesofbusiness";
$res = mysqli_query($con,$sql)or ("Error: ".mysqli_error($con));
while (list($id, $tob) = mysqli_fetch_row($res)); {
echo "<option value='$id'>$tob</option>\n";
}
?>
</select>
</td>
<td>
<span class="error">*
<?php if (isset($errors['typeofbusiness']))
echo $errors['typeofbusiness']; ?>
</span>
</td>
</tr>
这将创建下拉框并具有默认值:选择业务类型,但它似乎没有从数据库中提取数据,因为该值下没有其他选项。它还显示一条错误消息。
我不知道如何通过更改 or to or die 来解决,但是当我进行更改时,or die 下的所有代码都会出现,并且我还有另外 6-7 个字段,这确实不方便,甚至更糟,当我这样做时,没有出现错误消息。
我需要有人帮助我解决这些问题,以便它从数据库中提取信息并且所有其他错误不再出现。
错误是:
Warning: mysqli_fetch_row() expects parameter 1 to be mysqli_result, boolean given in C:\wamp\www\AddLeads\addeadstemplate.php on line 256 Call Stack # Time Memory Function Location 1 0.2188 192992 {main}( ) ..\addeadstemplate.php:0 2 2.1875 205216 mysqli_fetch_row ( ) ..\addeadstemplate.php:256
最佳答案
While 循环在 $error 变量之前关闭。
并且 Fetch 数组函数未用于 $error
<?php
$errors= mysql_fetch_array($res);
?>
<td><span class="error">* <?php if (isset($errors['typeofbusiness'])) { echo$errors['typeofbusiness']; }?></span></td>
</tr>
试试这个。
关于php - 隐藏 ID 列和其他显示数据的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20350998/