gpt4 book ai didi

PHP Switch case问题,总是返回错误

转载 作者:行者123 更新时间:2023-11-28 02:27:40 25 4
gpt4 key购买 nike

我有一个网页,我在其中输入一个字符串,然后通过 $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 的查询正在运行,而不是站名一。真奇怪。

最佳答案

您可能错过了 $select123 中的 ['value'] 和 case "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>

关于PHP Switch case问题,总是返回错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52892152/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com