php - PHP中的单选按钮和搜索文本框

标签 php mysql

我有我的输入表单:

<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

最佳答案

你需要错误中的连接,这样做就可以看到错误了。

mysqli_error($connection)

关于php - PHP中的单选按钮和搜索文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29799901/

相关文章:

PHP Word,将生成的文件作为输出发送到浏览器而不将其保存在光盘上

有空格的php yii表列名

php - 更改通过 session 变量选中的复选框

mysql - 无法连接到 Heroku 上的 JawsDB 实例

php - 我应该使用单独的 mysql 表吗

php - mysql PDO ON DELETE CASCADE - 不工作

php - 使用 PHP 显示 Mysql 数据给我一个空白页面

Php脚本不检查mysql表中的用户名值

mysql - 复杂定价矩阵的数据库结构

python - 无法使用 MySQLdb 创建游标