0

我的脚本在某处有问题,但不知道它到底在哪里不正确。这是代码:

<title>Log</title>
</head>

<h1> Log </h1>

<form method="get" action="getlog.php"> 

<table width="300" border="0">
  <tr>
    <td> Forte ID:</td>
    <td><select id="ForteID" name="ForteID">                    
                    <option value="nc4682">nc4682</option>
                    <option value="bs1441">bs1441</option>
                    <option value="sp3212">sp3212</option>                 
        </select></td>
  </tr>
</table>

 <input type="submit" name="getLog" value="Get Log">
 </form> 

</head>

<body>
</body>
</html>
<?php
/*print_r($_POST);*/
$serverName = 'SRB-Nick_Desktop\SQLEXPRESS';
$connectionInfo = array('Database'=>'cslogs', 'UID'=>'cslogslogin', 'PWD'=>'123456');
$connection = sqlsrv_connect($serverName, $connectionInfo);

$query = 'SELECT    ForteID, Disposition, appNumber, Finance_Num, Num_Payments, ACH_CC,     Notes from logs';

$result = sqlsrv_query($connection,$query);

if (!$result) 
{
    $message = 'ERROR: ' . sqlsrv_errors();
    return $message;
}
else
{
    $i = 0;
    echo '<html><body><table><tr>';
    while ($i < sqlsrv_num_rows($result))
    {
        $meta = sqlsrv_fetch($result, $i);
        echo '<td>' . $meta->name . '</td>';
        $i = $i + 1;
    }
    echo '</tr>';

    while ( ($row = sqlsrv_fetch_array($result))) 
    {
        $count = count($row);
        $y = 0;
        echo '<tr>';
        while ($y < $count)
        {
        $c_row = current($row);
        echo '<td>' . $c_row . '</td>';
        next($row);
        $y = $y + 1;
    }
    echo '</tr>';
}
sqlsrv_free_stmt ($result);

echo '</table></body></html>';
}
sqlsrv_close( $connection);
?>

这就是我得到的结果,无论在下拉框中选择什么并点击按钮获取日志。

nc4682 nc4682保存保存ASDF ASDF FDAS FDAS 1 1 CC CC ASDF ASDF bs1441 bs1441 LOC LOC AN00336862 AN00336862无无0 0 ACH ACH回退回退nc4682 nc4682保存保存AN00336862 AN00336862 easdf easdf 2 2 ACH ACH ASDF ASDF sp3212 sp3212塞尔塞尔NCXXXXXX1 NCXXXXXX1无无1 1 cc cc asdfasdfasdf asdfasdfasdf

每列都是重复的。应该有7列。

4

2 回答 2

0

sqlsrv_fetch_array()默认情况下返回数值数组和关联数组。

尝试仅指定一种类型的数组

while ( $row = sqlsrv_fetch_array( $result, SQLSRV_FETCH_ASSOC ))

在查询中使用您的 dropdpwn。

$query = 'SELECT    ForteID, Disposition, appNumber, Finance_Num, Num_Payments, ACH_CC,     Notes FROM logs WHERE ForteID =' . $_GET['ForteID'];

请注意,如果不清理 $_GET 变量,此查询很容易受到 sql 注入的攻击。

于 2012-11-06T20:30:33.617 回答
0

要仅显示下拉列表中的结果,您可以将 WHERE ForteID = {$_GET['ForteID']} 之类的内容附加到 SQL 语句的末尾。

于 2012-11-06T20:42:19.703 回答