I am trying to access a stored procedure, have it execute and using an html table to display the results. the code I have right now using PHP.net with an mssql_init and mssql_execute:
?php
$month = $_POST['month'];
$year = $_POST['year'];
$dayfrm = $_POST['creditfrm'];
$dayto = $_POST['creditto'];
$crdayfrm = date("F j, Y", strtotime($dayfrm));
$crdayto = date("F j, Y", strtotime($dayto));
$monthhd = date("F Y", strtotime("$year-$month"));
$monthfrm = date("Y-m-d", strtotime("$year-$month"));
$monthto = date("Y-m-d", strtotime("$year-$month . +1 month"));
echo $monthfrm;
echo $monthto;
$date = date("F j,Y");
$stopro = "usp_CreditMemo";
if ($_POST['credsubmit']) {
include('includes/header.php');
echo "<title>Credit Memo Report for $monthhd</title>";
print('<link rel="Shortcut Icon" href="liferay.ico" />');
print('<head>');
print('<link href="helper.css" media="screen" rel="stylesheet" type="text/css" />');
print('<link href="dropdown.css" media="screen" rel="stylesheet" type="text/css" />');
print('<link href="default.css" media="screen" rel="stylesheet" type="text/css" />');
// include('includes/connection.php');
// Performing SQL query
$db = mssql_connect("10.xx.xx.xx","UN","PW");
mssql_select_db("DBName",$db);
$stmt = mssql_init('usp_StoredName');
mssql_bind($stmt, '@dateFrom', '2012-05-01', 'SQLINT4', false, false, 20);
mssql_bind($stmt, '@dateTo', '2012-06-01', 'SQLINT4', false, false, 20);
$result = mssql_execute($stmt) or die('Query failed: ' . mssql_get_last_message());
// Printing results in HTML
echo "<h2 align=center style=margin-top:20>Credit Memo Report for: $monthhd</h2>";
echo "<table class=rptstable width=80%>\n";
print('<tr class="trstyle"><td>ID</td><td>DDI</td><td>Date</td><td>Amount</td><td>Name</td><td>Comments</td><td>Internal</td><td>Racker</td><td>Consolidated Inv.</td></tr>');
while ($line = mssql_fetch_array($result, MSSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";// Free resultset
mssql_free_result($result);// Closing connection
mssql_close($db);
}
When I do this I get a blank page. If I take out the mssql_bind's it gets an error saying that the stored procedure expects an @date input. But witht he binds it white pages with no error message display, which has always meant syntax errors. I would like to be able to pass the variable from the form called $monthfrm and $monthto but steps at a time.
Every once and a while depending on what I put in or take out I will get an error saying query failed: changed database context to "DBname".