0

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".

Zhorov
  • 28,486
  • 6
  • 27
  • 52
DoCnTex
  • 113
  • 2
  • 5
  • 11
  • just changed the mssql_binds to: mssql_bind($stmt, "@dateFrom", $monthfrm, SQLINT4); mssql_bind($stmt, "@dateTo", $monthto, SQLINT4); and got a new error: Query failed: Heterogeneous queries require the ANSI_NULLS and ANSI_WARNINGS options to be set for the connection. This ensures consistent query semantics. Enable these options and then reissue your query. – DoCnTex Jul 23 '12 at 16:41
  • added this bit of code to get rid of the above error and now it returns but with no data. Checked in MSSQL and there is data. $result = mssql_query("SET ANSI_NULLS ON"); $result = mssql_query("SET ANSI_WARNINGS ON"); – DoCnTex Jul 23 '12 at 17:42
  • Got it fixed. On the mssql_bind I was using SQLINT4 and it would not insert the right date so I used SQLCHAR and it is working. thanks. – DoCnTex Jul 23 '12 at 18:56

0 Answers0