我有一个带有三个参数 @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]." <td>".$rows[1]."
<td>".$rows[2]." <td>".$rows[3]."
<td>".$rows[4]." <td>".$rows[5]." ";
}
}
</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