使用 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 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))
{
//-----
}
谁能帮我解决这个问题吗?
最佳答案
用你的代码替换你的代码,然后希望它能正常工作。
<?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))
{
//-----
}
}
关于php - 从MySQL获取数据时出现 undefined variable 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33073702/