我有一个网页,在其中输入一个字符串,然后通过$ POST进入PHP脚本,在其中执行SQL选择,然后返回页面上的数据。对于一个单一的选择查询工作正常。但是我也试图包括其他Selects语句,以便同时搜索其他值。
因此,当我运行我的php(来自网页)时无需切换时,它始终会按预期运行。没有错误。
<html>
<!-- some style ... -->
<?php
$HOST="10.133.96.132";
// Database user
$DBUSER="tibco";
// Database password
$PASS="suyash123";
// Database name
$DB="VFD2TEST";
// Database Error - User Message
$DB_MSG_ERROR='Could not connect!<br />Please contact the site\'s administrator.';
############## Make the mysql connection ###########
$conn = oci_connect ($DBUSER, $PASS, "//10.133.96.132:7041/VFD2TEST");
if (!$conn) {
$m = oci_error();
echo $m['message'], "\n";
exit;
}
$select123 = $_POST['value'];
$output123 = shell_exec("cat data.lst |grep $select123| awk -F: '{print $2}'");
switch ($output123)
{
case "QUERY1":
$c = "SELECT * FROM EAITUXSERVICES WHERE TUX_ADAPTERS='".$_POST['value']."'";
$result = oci_parse($conn, $c);
oci_execute($result);
break;
case "QUERY2":
$c = "SELECT * FROM EAITUXSERVICES WHERE COMPONENT='".$_POST['value']."'";
$result = oci_parse($conn, $c);
oci_execute($result);
break;
case "QUERY3":
$c = "SELECT * FROM EAITUXSERVICES WHERE TUX_SERVICES='".$_POST['value']."'";
$result = oci_parse($conn, $c);
oci_execute($result);
default:
$c = "SELECT * FROM EAITUXSERVICES WHERE STATION_NAME='".$_POST['value']."'";
$result = oci_parse($conn, $c);
oci_execute($result);
break;
}
echo '<TABLE>';
echo '<thead>';
echo '<tr>
<th>ADAPTERS</th>
<th>SERVICE</th>
<th>CALLING_APP</th>
<th>BP_NAME</th>
<th>STATION_NAME</th>
<th style="padding-right:20px;">COMPONENT</th>
</tr>';
echo '</thead>';
while (($row = oci_fetch_array($result, OCI_BOTH)) != false)
{
echo '
<tr>
<td>'.$row[0].'</td>
<td>'.$row[1].'</td>
<td>'.$row[3].'</td>
<td>'.$row[4].'</td>
<td>'.$row[5].'</td>
<td>'.$row[6].'</td>
</tr>';
}
echo '</TABLE>';
oci_free_statement($result);
oci_close($conn);
?>
</html>
以下内容的输出是:
$select123 = $_POST['value'];
$output123 = shell_exec("cat data.lst |grep $select123| awk -F: '{print $2}'");
是QUERY1
所以它应该切换
=================================编辑============= ======================
我只是尝试了if else语句,尽管默认情况下列出的查询工作正常且与之相同,但第一个查询无论如何都不会获取数据。
================================================ =============================
================================ EDIT2 =============== =========================
现在我已经修剪了变量,所以没有空格或特殊字符的问题
<html>
<!-- some style ... -->
<?php
$HOST="10.xxx.xxx.132";
// Database user
$DBUSER="tibco";
// Database password
$PASS="xxxxx";
// Database name
$DB="TEST";
// Database Error - User Message
$DB_MSG_ERROR='Could not connect!<br />Please contact the site\'s administrator.';
############## Make the mysql connection ###########
$conn = oci_connect ($DBUSER, $PASS, "//10.xxxx.96.xx:xxx/xxxx");
if (!$conn) {
$m = oci_error();
echo $m['message'], "\n";
exit;
}
$select123 = $_POST['value'];
$output123 = shell_exec("cat data.lst |grep $select123| awk -F: '{print $2}'");
$output234 = trim($output123);
echo $output234;
if ($output234=="QUERY3")
{
$c = "SELECT * FROM EAITUXSERVICES WHERE COMPONENT='".$_POST['value']."'";
}
else if ($output234=="QUERY1")
{
$c = "SELECT * FROM EAITUXSERVICES WHERE TUX_ADAPTERS='".$_POST['value']."'";
}
$result = oci_parse($conn, $c);
oci_execute($result);
echo '<TABLE>';
echo '<thead>';
echo '<tr>
<th>ADAPTERS</th>
<th>SERVICE</th>
<th>CALLING_APP</th>
<th>BP_NAME</th>
<th>STATION_NAME</th>
<th style="padding-right:20px;">COMPONENT</th>
</tr>';
echo '</thead>';
while (($row = oci_fetch_array($result, OCI_BOTH)) != false)
{
echo '
<tr>
<td>'.$row[0].'</td>
<td>'.$row[1].'</td>
<td>'.$row[3].'</td>
<td>'.$row[4].'</td>
<td>'.$row[5].'</td>
<td>'.$row[6].'</td>
</tr>';
}
echo '</TABLE>';
oci_free_statement($result);
oci_close($conn);
?>
</html>
现在我的输出分别是QUERY1和QUERY3,但结果不存在,较早的查找STATION_NAME的查询正在运行,而查找COMPONENT的查询正在运行,而不是站点名称一个。真的很奇怪。
答案 0 :(得分:0)
您可能会错过$ select123中的['value']和大小写“ QUERY3”的中断。
然后您可以像这样简化代码:
$conn = oci_connect ($DBUSER, $PASS, "//YY.XXX.ZZ.132:XXXX/TEST");
if (!$conn) {
$m = oci_error();
echo $m['message'], "\n";
exit;
}
$select123 = $_POST;
$output123 = shell_exec("cat data.lst |grep $select123| awk -F: '{print $2}'");
$c = "SELECT * FROM EAITUXSERVICES WHERE ";
switch ($output123) {
case "QUERY1 ":
$c .= "TUX_ADAPTER";
break;
case "QUERY2 ":
$c .= "COMPONENT";
break;
case "QUERY3 ":
$c .= "TUX_SERVICES";
break;
default:
$c .= "STATION_NAME";
break;
}
$c .= "='".$_POST['value']."'";
$result = oci_parse($conn, $c);
oci_execute($result);
echo '<TABLE>';
echo '<thead>';
echo '<tr>
<th>ADAPTERS</th>
<th>SERVICE</th>
<th>CALLING_APP</th>
<th>BP_NAME</th>
<th>STATION_NAME</th>
<th style="padding-right:20px;">COMPONENT</th>
</tr>';
echo '</thead>';
while (($row = oci_fetch_array($result, OCI_BOTH)) != false)
{
echo '
<tr>
<td>'.$row[0].'</td>
<td>'.$row[1].'</td>
<td>'.$row[3].'</td>
<td>'.$row[4].'</td>
<td>'.$row[5].'</td>
<td>'.$row[6].'</td>
</tr>';
}
echo '</TABLE>';
oci_free_statement($result);
oci_close($conn);
?>
</html>
答案 1 :(得分:0)
我无法使用Switch语句运行它,但是可以在if ... else的帮助下完成它
这是代码
if (!$conn) {
$m = oci_error();
echo $m['message'], "\n";
exit;
}
$select123 = $_POST['value'];
$output123 = shell_exec("cat data.lst |grep $select123| awk -F: '{print $2}'");
$output234 = trim($output123);
if ($output234=="QUERY3")
{
$c = "SELECT * FROM EAITUXSERVICES WHERE COMPONENT='".$_POST['value']."'";
$result = oci_parse($conn, $c);
oci_execute($result);
}
//else if ($output234=="QUERY1")
//{
//$c = "SELECT * FROM EAITUXSERVICES WHERE TUX_ADAPTERS='".$_POST['value']."'";
//$result = oci_parse($conn, $c);
//oci_execute($result);
//}
else if ($output234=="QUERY2")
{
$c = "SELECT * FROM EAITUXSERVICES WHERE TUX_SERVICES='".$_POST['value']."'";
$result = oci_parse($conn, $c);
oci_execute($result);
}
else
{
$c = "SELECT * FROM EAITUXSERVICES WHERE STATION_NAME='".$_POST['value']."'";
$result = oci_parse($conn, $c);
oci_execute($result);
}
echo '<TABLE>';
echo '<thead>';
echo '<tr>
<th>ADAPTERS</th>
<th>SERVICE</th>
<th>CALLING_APP</th>
<th>BP_NAME</th>
<th>STATION_NAME</th>
<th style="padding-right:20px;">COMPONENT</th>
</tr>';
echo '</thead>';
while (($row = oci_fetch_array($result, OCI_BOTH)) != false)
{
echo '
<tr>
<td>'.$row[0].'</td>
<td>'.$row[1].'</td>
<td>'.$row[3].'</td>
<td>'.$row[4].'</td>
<td>'.$row[5].'</td>
<td>'.$row[6].'</td>
</tr>';
}
echo '</TABLE>';
oci_free_statement($result);
oci_close($conn);
?>
</html>
希望这对某人有帮助
答案 2 :(得分:0)
我认为真实答案应该只是trim
:
$output123 = trim(shell_exec("cat data.lst |grep $select123| awk -F: '{print $2}'"));
switch ($output123)
{
...
}