无法从所选复选框中获取数据

时间:2016-01-29 03:45:28

标签: php

这是html代码和php脚本,我无法查询所选复选框的数据:



 <code>

Search the Database using multiple options:<br /><br />

<form id="Advanced_form" action="checkbox.php" enctype="multipart/form-data" method="POST">

<input type="checkbox" name="checkbox1[]" value="1" /> Location: projectid
<input type="text" name="projectid" size="10" /> basesq30 from 
<input type="text" name="start" size="10" /> To 
<input type="text" name="end" size="10" />
<br /><br />

<input type="checkbox" name="checkbox1[]" value="2" /> platform:

<select name="key4" onchange="SetText(key4,word4)">
<option selected="selected" value="All">Select</option>
<option value="miseq">miseq</option>
<option value="hiseq">hiseq</option>

</select>.<br /><br />
<input type="checkbox" name="Genotype" value="3" /> run no:
<select multiple="multiple" name="checkbox1[]" size="5">
<option selected="selected" value= "2">2</option>
<option value= "3">3</option>
<option value= "4">4</option>
<option value= "5">5</option>
<option value= "6">6</option>
</select>

<center>
<INPUT TYPE="Reset" VALUE="Reset">
<input style="align: center;" type="Submit" name="submit" value="Search" /></center>

</form>
<?php
/*
Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password)
*/
$link = mysqli_connect("localhost", "root", "root123", "newdb");
 
// Check connection
if($link === false)
{
    die("ERROR: Could not connect. " . mysqli_connect_error());
}
//code
if(isset($_POST['submit']))
{
    foreach($_POST['checkbox1'] as $checkbox1)
    //printf("%S<br>",$checkbox1);

    if($checkbox1==1)
        $text=$_POST['projectid'];
    $a=$_POST['start'];
    $b=$_POST['end'];
    {
        $sql="select * from qcdata where project_id='$text' and bases_q30>='$a' and bases_q30<='$b'";
    }
    if($checkbox1==2)
    {
        $value=$_POST['key4'];
        $sql1="select * from qcdata where platform='$value'";
    }
}

echo "$sql";

if($result = mysqli_query($link, $sql))
{
    if(mysqli_num_rows($result) > 0)
    {
        echo "<table align='left'>";
        echo "<tr>";
        echo "<th>sno</th>";
        echo "<th>project_id</th>";
        echo "<th>file_name</th>";
        echo "<th>read_pair</th>";
        echo "<th>total_bases</th>";
        echo "<th>total_reads</th>";
        echo "<th>bases_q20</th>";
        echo "<th>bases_q30</th>";
        echo "<th>average_read_length</th>";
        echo "<th>readlength_range_min</th>";
        echo "<th>readlength_range_max</th>";
        echo "<th>quality_range_min</th>";
        echo "<th>quality_range_max</th>";
        echo "<th>phread_range_min</th>";
        echo "<th>phread_range_max</th>";
        echo "<th>gc_percentage</th>";
        echo "<th>a</th>";
        echo "<th>t</th>";
        echo "<th>g</th>";
        echo "<th>c</th>";
        echo "<th>n</th>";
        echo "<th>platform</th>";
        echo "<th>run_no</th>";
        echo "<th>creation_by</th>";
        echo "<th>creation_date</th>";
        echo "<th>last_modified</th>";

        echo "</tr>";
        
        while($row = mysqli_fetch_array($result))
        {
            echo "<tr>";
            echo "<td>" .$row['sno'].  "</td>";
            echo "<td>" .$row['project_id'] . "</td>";
            echo "<td>" .$row['file_name']. "</td>";
            echo "<td>" .$row['read_pair'] . "</td>";
            echo "<td>" .$row['total_bases'] . "</td>";
            echo "<td>" .$row['total_reads'] . "</td>";
            echo "<td>" .$row['bases_q20'] . "</td>";
            echo "<td>" .$row['bases_q30'] . "</td>";
            echo "<td>" .$row['average_read_length'] . "</td>";
            echo "<td>" .$row['readlength_range_min'] . "</td>";
            echo "<td>" .$row['readlength_range_max'] . "</td>";
            echo "<td>" .$row['quality_range_min'] . "</td>";
            echo "<td>" .$row['quality_range_max'] . "</td>";
            echo "<td>" .$row['phread_range_min'] . "</td>";
            echo "<td>" .$row['phread_range_max'] . "</td>";
            echo "<td>" .$row['gc_percentage'] . "</td>";
            echo "<td>" .$row['a'] . "</td>";
            echo "<td>" .$row['t'] . "</td>";
            echo "<td>" .$row['g'] . "</td>";
            echo "<td>" .$row['c'] . "</td>";
            echo "<td>" .$row['n'] . "</td>";
            echo "<td>" .$row['platform'] . "</td>";
            echo "<td>" .$row['run_no'] . "</td>";
            echo "<td>" .$row['creation_by'] . "</td>";
            echo "<td>" .$row['creation_date'] . "</td>";
            echo "<td>" .$row['last_modified'] . "</td>";
            echo "</tr>";
        }
        echo "</table>";
        // Close result set
        mysqli_free_result($result);
    }
    else{
        echo "No records matching your query were found.";
    }
}
else {
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
} 
 
// Close connection
mysqli_close($link);
?>
</code>
&#13;
&#13;
&#13;

MySQL数据库截图图片在part 1 part 2

1 个答案:

答案 0 :(得分:0)

我会从复选框的名称中删除[]。