Hi
I am trying to get certain values from a php form that interacts with the MySQL database. It contains the following field.
- Organism: a select button to ask whether the organism is human, rat or mouse.
- GenomeVersion: (select button) On the basis of organism it query the database table and populate another select field
- QueryType: a Radio button to select the type of the query. It has two possible option (a. fasta, b:idList)
- if response in 3 is idList then another field called 'arrType' is created. This is a select button and the entries are populated from database.
In the following code as soon as I select 4th field ('arrType'), the 'queryType' (3rd field) reset and 'arrType' select option button vanishes.
I suppose that this may be because of the autoSubmit() function of the javascript.
What is the correct way to do it so that I do not lose these information.
Thanks
<?php
$conn = mysql_connect('localhost', 'root', 'fahim');
$db = mysql_select_db('rugit',$conn);
if (!$db) die("Unable to connect to MySQL: " . mysql_error());
?>
<?php
$organism = $genomeVer = $queryType = $arrType = null; //declare vars
if(isset($GET["organism"]) && is_string($GET["organism"]))
{
$organism = $GET["organism"];
}
if(isset($GET["genomeVer"]) && is_string($GET["genomeVer"]))
{
$genomeVer = $GET["genomeVer"];
}
if(isset($GET["queryType"]) && is_string($GET["queryType"]))
{
$queryType = $GET["queryType"];
}
if(isset($GET["arrType"]) && is_string($GET["arrType"]))
{
$queryType = $GET["arrType"];
}
?>
<script language="JavaScript">
function autoSubmit()
{
var formObject = document.forms['theForm'];
formObject.submit();
}
</script>
<form name="theForm" method="get" enctype="multipart/form-data">
<select name="organism" onChange="autoSubmit();">
<option value="null">Select Organism</option>
<option value= "human" <?php if(strcmp($organism, "human") == 0) echo " selected"; ?>>human</option>
<option value= "mouse" <?php if(strcmp($organism, "mouse") == 0) echo " selected"; ?>>mouse</option>
<option value= "rat" <?php if(strcmp($organism,"rat") == 0) echo " selected"; ?>>rat</option>
</select> <br></br>
<?php
if ($organism == null){ print "Select an Organism!!!!!!!!\n"; exit;}
elseif($organism != null && is_string($organism))
{
//POPULATE DROP DOWN MENU WITH COUNTRIES FROM A GIVEN organism
$sql = "SELECT genomeVer FROM organismGenomeVer WHERE organism = \"$organism\"";
//print("sql is $sql");
$result = mysql_query($sql,$conn);
//print("result is $result");
?>
<br>
<select name="genomeVer" onChange="autoSubmit();">
<option value="null">genomeVer</option>
<?php
while($row = mysql_fetch_array($result))
{
echo ("<option value=\"$row[0]\" " . ($genomeVer == $row["0"] ? " selected" : "") . ">$row[0]</option>");
}
mysql_free_result($result);
?>
</select>
<?php
//print "\n\nselected genome version is $genomeVer\n\n\n\n";
}
if ($organism != null && $genomeVer == null) { print "Select genome Version!!!!!!!!\n"; exit;}
?>
<br><br>
Identifier(s) as query : <input type="radio" value="idList" name="queryType" <?php if ($queryType == "idList") echo "checked"; ?> onclick="autoSubmit();" > <BR>
Fasta Seq(s) as query: <input type="radio" value="seqList" name="queryType" <?php if ($queryType == "seqList") echo "checked"; ?> onclick="autoSubmit();"> <BR></br>
<?php
if ($organism==null || $genomeVer==null || $queryType==null)
{
echo '<span style="color:red">';
echo ("error in input selection. Try Again!!!!!!!!!!");
//return;
}
if ($queryType == "idList")
{
$organism = 'human';
print("inside php tag");
$query = strtolower("show tables like \"$organism%\"");
print("query is $query");
$result = mysql_query($query, $conn);
$nRows = mysql_num_rows($result);
print"nRows is $nRows";
?>
<br></br>
<select name="arrType" onChange="autoSubmit();">
<option value="null">Select arrType</option>
<option value="notSure" <?php if($arrType == 'notSure') echo " selected"; ?>>Not sure</option> <br></br>
<?php
while($row = mysql_fetch_array($result))
{
echo ("<option value=\"$row[0]\" " . ($arrType == $row["0"] ? " selected" : "") . ">$row[0]</option>");
}
mysql_free_result($result);
echo"</select><br>";
} //end if
print ("$organism, $genomeVer, $queryType, $arrType");
?>
</form>