0

我有一个带有三个参数 @startdate、@enddate 和 @field1 的存储过程,当我尝试执行以下 php 代码时,出现错误

未定义索引:开始日期未定义索引:结束日期未定义索引:field1

<?php
$myServer = "instance_name"; // host/instance_name
$myUser = "username"; // username
$myPass = "password"; // paasword
$myDB = "databasename"; // database name
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
or die("Couldn’t connect to SQL Server on $myServer");
$selected = mssql_select_db($myDB, $dbhandle)
or die("Couldn’t open database $myDB");

<?php
$startdate = isset($_REQUEST['startdate']) ? $_REQUEST['startdate'] : null;
$enddate = isset($_REQUEST['enddate']) ? $_REQUEST['enddate'] : null;
$field1 = isset($_REQUEST['field1']) ? $_REQUEST['field1'] : null;
?>

<form action = "thisfile.php" method = "post">
Please input startdate <input type = "text" name = "startdate" /> </br>
Please input enddate <input type = "text" name = "enddate" /> </br>
Please input field1 name <input type = "text" name = "field1" /> </br>
Please submit <input type = "submit" name = "submit" value = "submit" /> </br>
</form>

<table border = "5" id="1">

 <?php
    if (isset($startdate) && isset($enddate) ){
$query = "storedprocedure '$startdate','$enddate','field1'";
    $result = mssql_query($query);
while ($rows = mssql_fetch_array($result) ) {
echo "<tr><td>".$rows[0]."&nbsp;<td>".$rows[1]."&nbsp;
   <td>".$rows[2]."&nbsp;<td>".$rows[3]."&nbsp;
    <td>".$rows[4]."&nbsp;<td>".$rows[5]."&nbsp;";
}
}

</table>
</body>
</html>

我只是在顶部寻找三个文本框,当我在文本框中输入 startdate、enddate 和 field1 名称时,它应该在同一页面中显示输出。

编辑:我的存储过程类似于以下内容:

Create procedure storedprocedure
@startdate datetime,
@enddate datetime,
@field1  varchar(50)
select date, sum(qty), sum(qty), sum(qty2), sum(qty3), sum(qty4) from table1
where date between @startdate and @enddate and field1 like @field1 + '%'
group by date
4

2 回答 2

0

你为什么不试试这个

if (isset($startdate) && isset($enddate) ){
$query = "storedprocedure '$startdate','$enddate','field1'";
    $result = mssql_query($query);
while ($rows = mssql_fetch_array($result) ) {
echo "<tr><td>".$rows[0]."&nbsp;<td align=right>".$rows[1]."&nbsp;
   <td align=right>".$rows[2]."&nbsp;<td align=right>".$rows[3]."&nbsp;
    <td align=right>".$rows[4]."&nbsp;<td align=right>".$rows[5]."&nbsp;";
}
}

这应该停止通知

于 2012-08-18T22:29:56.807 回答
0

您可以通过以下方式重写部分代码:

<?php
    $startdate = isset($_REQUEST['startdate']) ? $_REQUEST['startdate'] : null;
    $enddate = isset($_REQUEST['enddate']) ? $_REQUEST['enddate'] : null;
    $field1 = isset($_REQUEST['field1']) ? $_REQUEST['field1'] : null;
?>

但实际上您需要检查所有请求参数(尤其是enddatefield1)是否存在。

另请参阅http://php.net/manual/en/language.types.array.php

于 2012-08-18T22:39:37.020 回答