Php 从MySQL获取数据时出现未定义变量错误
使用PHP从MySQL数据库获取数据时出错Php 从MySQL获取数据时出现未定义变量错误,php,html,mysql,Php,Html,Mysql,使用PHP从MySQL数据库获取数据时出错 Undefined variable: result in C:\wamp\www\mbdb\Biomarkerresult1.php on line 20 mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in C:\wamp\www\mbdb\Biomarkerresult1.php on line 20 我的下拉列表编码: <select n
Undefined variable: result in C:\wamp\www\mbdb\Biomarkerresult1.php on line 20
mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in C:\wamp\www\mbdb\Biomarkerresult1.php on line 20
我的下拉列表编码:
<select name="names" value="name">
<option value="Biomarker">Select a Biomarker</option>
<option value="Diagnostic">Diagnostic</option>
<option value="Prognsotic">Prognostic</option>
<option value="Predictive">Predictive</option>
下面显示数据:
<?php
$con=mysqli_connect('localhost','root','','mbdb');
if(mysqli_errno($con))
{
echo "Can't Connect to mySQL:".mysqli_connect_error();
}
if(isset($_POST['names']))
{
$name = $_POST['names'];
$fetch="SELECT * FROM metabolites WHERE Biomarker_Category = '".$name."'";
$result = mysqli_query($con,$fetch);
}
while($row=mysqli_fetch_array($result))
{
//-----
}
有人能帮我解决这个问题吗?在错误的末尾,您会看到: mysqli_fetch_数组期望参数1是mysqli_结果,在第20行的C:\wamp\www\mbdb\biomarkeresult1.php中给出null
这使我相信您的查询没有返回任何内容,因此$result被定义为null。为了检查这一点,我会在尝试while循环之前检查$result是否为null 用你的代码替换你的代码,希望它能正常工作
<?php
$con=mysqli_connect('localhost','root','','mbdb');
if(mysqli_errno($con))
{
echo "Can't Connect to mySQL:".mysqli_connect_error();
}
if(isset($_POST['names']))
{
$name = $_POST['names'];
$fetch="SELECT * FROM metabolites WHERE Biomarker_Category = '".$name."'";
$result = mysqli_query($con,$fetch);//Seems to be your your posting the data, or u'r using get and post for the same form
while($row=mysqli_fetch_array($result))
{
//-----
}
}
您的生物标记物类别是否正确。?您的$result变量为空。首先检查您对phpmyadmin.put的查询,然后将其放入If感谢您的答复。我在上面给出了我的下拉列表编码。我需要知道我的下拉列表值是否通过变量“$name”获取。在phpadmin中运行此查询时,我得到了所需的输出。1。您的帖子对SQL注入开放-使用准备好的语句并绑定您的变量。2.你不能只是在字符串中粘贴一个数组-它不会神奇地为你做这件事-你必须遍历数组并将这些项逐个添加到你的SQL查询中-你可以在其中使用SQL函数-但是要确保你绑定了你的变量!谢谢你,吉坦德拉·库马尔。但是我没有得到我应该在我的代码中做什么更改。你必须在if语句中循环时编写。我已经编辑了那个部分。但我仍然没有在输出页面中获得结果表。最好进行调试并添加注释。您得到的错误是什么