【发布时间】:2015-07-16 12:40:52
【问题描述】:
现在我真的很困惑,并且已经在这个问题上工作了几个小时,所以我想我会在这里发帖,也许会得到一些反馈。所以我有一个程序可以在文件上运行这个搜索工具。该文件要么来自生成到文件中的用户输入,要么来自实际上传文件的用户。我有 2 个提交按钮,其中第一个与用户生成的文件有关,第二个与用户上传文件有关。
我遇到的问题是第二个提交按钮的代码完全相同(所有更改都是程序获取文件的方式),但由于某种原因,第二个提交按钮不起作用。没有生成任何内容,也不会执行搜索工具。我知道这一点,因为没有创建输出文件。
我想知道是否有人知道为什么我的第二个按钮不像第一个按钮那样执行......
这是我的代码...
<form method="POST", action="/~cs4380sp15grp4/home/blast.php" class="form-inline">
<textarea id="BlastSearch" type="textarea" name="BlastSearch" class="form-control">
Database:
<select id="database" name="database" class="form-control">
<option value="Archaea">Archaea</option>
</select>
Threshold:
<select id="evalue" name="evalue" class="form-control">
<option value="0.0001">0.0001</option>
<option value="0.001">0.001</option>
</select>
Hits:
<select id="hits" name="hits" class="form-control">
<option value="50">50</option>
<option value="100">100</option>
</select>
<button id="run" type="submit" name="submit" class="btn btn-primary"><span class="glyphicon glyphicon-wrench"></span> Run BLAST</button>
<button type="reset" value="Clear" class="btn btn-info">Clear</button>
</form>
<form enctype="multipart/form-data" action="upload.php" method="POST" class="form-inline"/>
<input type="file" name="fileToUpload" id="fileToUpload" class="form-control"/>
<input type="submit" value="upload" name="upload" class="form-control"/>
<input type="reset" value="reset" name="reset" class="form-control"/>
</form>
<form method="POST", action="/~cs4380sp15grp4/home/blast.php" class="form-inline">
<input type="submit" value="submit file" name="submit2" class="form-control"/>
</form>
<?php
//connects to db
//Insert the values into the database
if(isset($_POST['submit'])){
//declare variables to what the user defines them as
$db = $_POST['database'];
$evalue = $_POST['evalue'];
$sequence = $_POST['BlastSearch'];
$hits = $_POST['hits'];
//create a new .fasta file and put the sequence the user wants to search for in that file
$file = 'uploads/'.$mysqli->insert_id.'.fasta';
$header = ">gi|129295|sp|P01013|OVAX_CHICK GENE X PROTEIN (OVALBUMIN-RELATED)\n";
$current = $header . $_POST['BlastSearch'];
file_put_contents($file, $current);
$userid = $_SESSION['uid'];
//insert the values into the database
$mysqli->query("INSERT INTO `Job` (`uid`, `input`, `status`, `start_time`, `finish_time`) VALUES ('1', '" . $sequence . "', 'running' , NOW(), NOW())");
$mysqli->query("INSERT INTO `BLAST`(`db_name`, `evalue`, `job_id`) VALUES ('" . $db . "','" . $evalue . "', '".$mysqli->insert_id."')") or die(mysqli_error($mysqli));
//execute the BLAST Tool
// Do this execute statement if the user inputs his own sequence. (Use new.fasta)
exec('/students/groups/cs4380sp15grp4/blast/blast-2.2.26/bin/blastall -p blastp -d db -i /students/groups/cs4380sp15grp4/public_html/home/uploads/'.$mysqli->insert_id.'.fasta -m'.$evalue.' -o outputSEQ -v'.$hits.' -b'.$hits);
}
if(isset($_POST['submit2'])){
//declare variables to what the user defines them as
$db = $_POST['database'];
$evalue = $_POST['evalue'];
$sequence = $_POST['BlastSearch'];
$hits = $_POST['hits'];
$userid = $_SESSION['uid'];
//insert the values into the database
$mysqli->query("INSERT INTO `Job` (`uid`, `input`, `status`, `start_time`, `finish_time`) VALUES ('1', '" . $sequence . "', 'running' , NOW(), NOW())");
$mysqli->query("INSERT INTO `BLAST`(`db_name`, `evalue`, `job_id`) VALUES ('" . $db . "','" . $evalue . "', '".$mysqli->insert_id."')") or die(mysqli_error($mysqli));
exec('/students/groups/cs4380sp15grp4/blast/blast-2.2.26/bin/blastall -p blastp -d db -i /students/groups/cs4380sp15grp4/public_html/home/uploads/sample.fasta -m '.$evalue.' -o outputFILE -v'.$hits.' -b'.$hits);
}
$mysqli->close();
?>
我不明白。基本上 exec 函数在第一个提交按钮中工作,但 exec 函数在第二个按钮中不起作用......我可以进入终端并运行第二个 exec 函数,它运行得很好。是因为第二次提交的动作是upload.php吗?我可以看到它是......
EDIT1:我刚刚尝试专门为该按钮创建一个新表单,并使操作与第一个提交按钮表单相同。虽然它没有工作:(任何帮助表示赞赏!
【问题讨论】:
-
我不明白你为什么要用三种形式?
-
不能通过另一个表单提交按钮获取其他表单域,所以不会得到 $_POST['database'];在第二个提交按钮中,这就是您的查询引发错误的原因。你应该启用显示错误来获得它。
-
但是您只有第一个表单中的输入,因此您只有在发布第一个表单时才发布它们。正如 sємsєм 所说,您需要将所有表单(具有相同操作)合并为一个,然后您可以检查您单击了哪个提交按钮。
-
除了你的代码中的错误之外,比如一个额外的逗号等。你能解释一下你试图用这三种形式实现什么功能吗?当第二个表单 submit2 没有这些字段时,您正试图在第二种情况下获得像 $_POST['database'] 这样的文件。建议重新考虑用例并重做表单,您也许可以仅使用一个表单完成此操作。
-
我回滚了编辑,因为问题已完全重写,因此答案没有任何意义。