By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,064 Members | 1,449 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,064 IT Pros & Developers. It's quick & easy.

PHP web form Call MSSQL stored procedure, display search results

geforceGTX480
P: 1
So, I can't seem to get a sample code that works.
I have a web form that will have input fields. These fields will be used as input parameters for the MSSQL stored procedure.
From there we are expecting to get results depending on what
user is searching for.
I don't have access to view the stored procedure code, but I have execute permissions. Below is my code. I can successfully connect, but I do not get any results. In fact I get 0 results.
Is there anything I am missing? Can't use MySQL coz this is an IIS Server;
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // Connection settings
  3. $host = '#####';
  4. $user = '######';
  5. $pass = '######';
  6.  
  7. if ($conn = mssql_connect($host, $user, $pass)) // connection string
  8. {
  9. echo 'connected to Host <br/> ';
  10. }
  11.  
  12. // select database
  13. if (mssql_select_db('USAHerds', $conn)) { 
  14. echo ' and DB selected ';
  15. }
  16.  
  17.  
  18. $query = mssql_init("procAnimalBrandLicensesSearch", $conn) or die("Couldn't call stored procedure");
  19. $AcctFirstNames = $_GET['AcctFirstName'];
  20.  
  21. mssql_bind($query, "@AcctFirstName", $AcctFirstNames, SQLVARCHAR, FALSE, FALSE, 20);
  22.  
  23.  
  24. $result = mssql_execute($query);
  25.  
  26. $numProds = mssql_num_rows($result); 
  27.  
  28. echo "<h1>" . $numProds . " Result" . ($numProds == 0 ? "" : "s") . " Found for : $AcctFirstNames </h1><table border=\"1\"><tr>
  29.    <th>First Name</th>
  30.     <th>Last Name</th>
  31.     <th>File Name</th>
  32.   </tr>";
  33.  
  34. while($row = mssql_fetch_row($result)) 
  35.  
  36.  
  37. echo "<tr>" ."<td>" .$row["AcctFirstName"] ."</td>"."<td>". $row["AcctLastName"]."</td>". "<td>".$row["FileName"]. "</td>"."</tr>"; 
  38.  
  39. }
  40. echo "</table>";
  41.  
  42.  
  43. ?> 
  44.  
  45.  
Thanks for your help
Dec 21 '11 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.