【发布时间】:2023-03-28 13:00:03
【问题描述】:
我有我的输入表单:
<form style="font-size: 10pt; font-family: 'Courier New'; color:black;font-weight:600;margin-left:15px;line-height:25px" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="radio" id="a" name="search" value="EntryId" checked>EntryId <font color="blue">(get Vocab information)</font>
<br />
<input type="radio" id="b" name="search" value="EntryId1">EntryId <font color="blue">(get disease name, protein name)</font>
<br />
<input type="radio" id="c" name="search" value="UniprotId">UniprotId <font color="blue">(get Gene name, Dna Seq)</font>
<br />
<input type="radio" id="d" name="search" value="Genename">Genename <font color="blue">(get Gene information)</font>
<br />
<input type="radio" id="e" name="search" value="EntryId3">EntryId <font color="blue">(get HTML, PubMed information)</font>
<br /><br /><br />
<input style="height:30px; width: 300px; border:black 1px solid" type="text" name="Search" >
<input style="height:30px" type="submit" value="Go">
</form>
在这个表单中,我使用了六个单选按钮,每个按钮代表一个存储在 MySQL 中的存储过程。如果我选择一个单选按钮并在文本框中输入一个值(这将是我选择的过程的参数),我想要该过程的输出。
PHP 代码:
<?php
$id='';
$query='';
if (isset($_POST['Search']))
{
$id=$_POST['Search'];
}
echo "<table>";
//connect to database
$connection = mysqli_connect("localhost", "root", "", "mohammad_prostatecancer");
//run the store proc
if (isset($_POST['EntryId1']))
{
$query= "call DiseaseVocab(".'"'.$id.'")';
}
if (isset($_POST['EntryId2']))
{
$query= "call DiseaseProtein(".'"'.$id.'")';
}
if (isset($_POST['UniprotId']))
{
$query= "call getGene(".'"'.$id.'")';
}
if (isset($_POST['Genename']))
{
$query= "call Getname(".'"'.$id.'")';
}
if (isset($_POST['EntryId3']))
{
$query= "call Getdata(".'"'.$id.'")';
}
$result = mysqli_query($connection, $query) or die("Query fail: " . mysqli_error());
//loop the result set
echo "<tbody>";
// point to the beginning of the array
$check = mysqli_data_seek($result, 0);
?>
<tr>
<td><b>EntryId</b></td>
<td><b>Vocabid</b></td>
<td><b>VocabSourceName</b></td>
</tr>
<?php
while ($rownew = mysqli_fetch_assoc($result)) {
echo "<tr>";
foreach($rownew as $k => $v)
{
echo "<td>".$v."</td>";
}
echo "</tr>"."<br>";
}
echo "</tbody></table>";
?>
我没有得到任何结果。我收到以下警告:
Warning: mysqli_query(): Empty query
Warning: mysqli_error() expects exactly 1 parameter, 0 given
【问题讨论】:
-
将您的
if (isset($_POST['EntryId1']))更改为if (isset($_POST['search']) && $_POST['search'] == 'EntryId1'),以及所有其他类似 -
我更改了名称并尝试使用您的代码..它仍然给我同样的警告..
-
现在我得到了结果,但是当我第一次加载页面时,它警告我 $query 为空.. 你有什么解决方案吗?
-
您需要为
$query设置默认值或将所有代码放入您的if (isset($_POST['Search'])){...} -
改进了源代码格式以提高可读性。