2017-06-14 30 views
-2
<form method="post" action="newrs.php" target="_blank" enctype="multipart/form-data" > 
<table> 
<tr> 
<td><font style="font-size:20px">Snp Id:</font></td> 
<td><input type="text" name="isnp_id" id="idsnp_id" placeholder="Ex:SCcLG07_1001342" size=20 style="font-size:18px"></td> 
</tr> 
<tr> 
<td><font style="font-size:20px">Gene Id:</font></td> 
<td><input type="text" name="igene" id="idgene" placeholder="Ex:C.cajan_17400" size=20 style="font-size:18px"></td> 
</tr> 
<tr> 
<td><font style="font-size:20px">Chromosome:</font></td> 
<td><input type="text" name="ichr" id="idchr" placeholder="Ex:CcLG07" size=20 style="font-size:18px"></td> 
<td> position from </td> 
<td><input type="text" name="posstart" id="idposstart" placeholder="Ex: 1" size="20"> to <input type="text" name="posend" id="idposend" placeholder="Ex:100" size="20"> 
</td> 
</tr> 
<tr> 
<td><font style="font-size:20px">Effect:</font></td> <td><input type="text" name="ieff" id="ideff" placeholder="Ex:Low, High, Moderate" size=20 style="font-size:18px"></td> 
</tr> 
</table> 
<br/> 
<span><font style="font-size:22px;color:green">Options:</font></span><br/> 
<table> 
<tr> 
<td><input type="checkbox" name="cb" value="cb_class" /></td><td><font style="font-size:20px">Classification:</font></td> 
<td><select style="font-size:18px" name="sclass" > 
<option value="all" selected="selected">Select</option> 
<option value="intergenic">Intergenic</option> 
<option value="intronic">Intronic</option> 
<option value="non_synonymous_coding">Non Synonymous Coding</option> 
<option value="synonymous_coding">Synonymous Coding</option> 
</select> </td> 
</tr> 
<tr> 
<td><input type="checkbox" name="cb" value="cb_vtype" /></td><td><font style="font-size:20px">Varation Type:</font></td> 
<td><select style="font-size:18px" name="svtype" > 
<option value="all" selected="selected">Select</option> 
<option value="snp">Snp</option> 
<option value="insertion">Insertion</option> 
<option value="deletion">Deletion</option> 
</select> </td> 
</tr> 
<tr> 
<td><input type="checkbox" name="cb" value="cb_fc" /></td><td><font style="font-size:20px">Functional Class:</font></td> 
<td><select style="font-size:18px" name="sfunclass" > 
<option value="all" selected="selected">Select</option> 
<option value="missense">Missense</option> 
<option value="nonsense">Nonsense</option> 
<option value="silent">silent</option> 
</select> 
</td> 
</tr> 

<tr> 
<td></td><td></td> 
<td><input type="reset" name ="reset" value="Reset" style="font-size:18px"> 
<input type="submit" name="submit" value="Search" style="font-size:18px"> </td> 
</tr> 
</table> 
</form> 
    php code starts here: 
    <?php 
include_once 'connect.php'; 
if(isset($_POST['submit'])) 
{ 
$selected_cb=$_POST['cb']; 
if(($gene=$_POST['igene']) && ($selected_cb=='cb_class') && ($selected_cb=='cb_vtype')) 
{ 
    $selectc=$_POST['sclass']; 
    if($selectc=='intergenic') 
    { 
    $selectv=$_POST['svtype']; 
     switch($selectv) 
     { 
     case "snp":   
       $sql="select snp_eff.*,variations_categorised.variation_type from snp_eff inner join variations_categorised on snp_eff.snp_id = variations_categorised.snp_id where snp_eff.classification ='INTERGENIC' AND snp_eff.transcript like '%$gene%' AND variations_categorised.variation_type='SNP' LIMIT 1000"; 
      break; 
      case "insertion":   
       $sql="select snp_eff.*,variations_categorised.variation_type from snp_eff inner join variations_categorised on snp_eff.snp_id = variations_categorised.snp_id where snp_eff.classification ='INTRONIC' AND snp_eff.transcript like '%$gene%' AND variations_categorised.variation_type='INSERTION' LIMIT 1000"; 
     break; 
     case "deletion":   
      $sql="select snp_eff.*,variations_categorised.variation_type from snp_eff inner join variations_categorised on snp_eff.snp_id = variations_categorised.snp_id where snp_eff.classification ='NON_SYNONYMOUS_CODING' AND snp_eff.transcript like '%$gene%' AND variations_categorised.variation_type='DELETION' LIMIT 1000"; 
        break; 
     } 
    } 
    } 
    } 
$counter=0; 
if($result = pg_query($link, $sql)) { 
if(pg_numrows($result) > 0) { 
?> 
    <table id="t01" > 
    <tr > 
<th>sno</th> 
<th>chr</th> 
<th>pos</th> 
<th>snp_id</th> 
<th>ref_base</th> 
<th>alt_base</th> 
<th>classification</th> 
<th>effect</th> 
<th>functional class</th> 
<th>variation type</th> 
<th>Gene ID</th> 
</tr> 
    <?php 
    while($row = pg_fetch_array($result)){ 
    ?> 
     <tr> 
      <td><?php echo ++$counter ;?> </td>  
      <td><?php echo $row['chr'] ;?> </td> 
      <td><?php echo $row['position'] ;?> </td> 
      <td><?php echo $row['snp_id'] ;?> </td>         
      <td><?php echo $row['ref'] ;?> </td> 
      <td><?php echo $row['alt'] ;?> </td> 

      <td><?php echo $row['classification'] ;?> </td> 
      <td><?php echo $row['effect'] ;?> </td> 
      <td><?php echo $row['functional_class'] ;?> </td> 
      <td><?php echo $row['variation_type'] ;?> </td> 
      <td><?php echo $row['transcript'] ;?> </td> 
      </tr> 

     <?php 
     } 
    } 
    else{ 
     echo " No records matching your query were found."; 
    } 
    } 
?> 
</table> 

我在使用三種組合搜索記錄時沒有得到任何結果。在Apache日誌它顯示錯誤:我無法在PHP中執行我的代碼

未定義的變量:SQL

我想不出什麼我錯過了這個代碼的東西。

+0

您能顯示connect.php文件嗎? –

+2

你得到那個錯誤是因爲'$ sql'並不總是被設置。它只在執行'switch()'的時候被設置,並且如果頁面從不提交,它將永遠不會被設置。 – Daniel

+1

'if(($ gene = $ _ POST ['igene'])&&($ selected_cb =='cb_class')&&($ selected_cb =='cb_vtype'))'< - 確定您想使用'=='而不是你的IF語句中的'='。 – Twinfriends

回答

0

您得到該錯誤的原因是因爲$sql變量不總是被設置。

當你到下面的代碼,並在頁面尚未submittied,該$sql變量是無處可尋:

if($result = pg_query($link, $sql)) { 

您應該檢查,如果表單已經提交,然後檢查數據庫結果。

if(isset($_POST['submit'] && $result = pg_query($link, $sql)) { 
+0

if(isset($ _ POST ['submit']我在代碼頂部使用了這個 –

+0

你是對的,但查詢不在if語句裏面。 – Daniel