gpt4 book ai didi

php - 从MySQL获取数据时出现 undefined variable 错误

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

使用 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/

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