Advanced Search

Results 1 to 2 of 2

Thread: sqlsrv_fetch_array() Error

  1. #1
    Join Date
    Oct 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default sqlsrv_fetch_array() Error

    Hello everyone. I have a database (SQL server 2008 R2) that I finally got PHP5 installed on. I Can run basic simple querries against the DB without problem. I am now trying to allow a user to search the database by drop down menus and text fields to narrow a search down and am running into a few problems. Any advice would be greatly appreciated.

    Error Message:
    Warning: sqlsrv_query() expects at least 2 parameters, 1 given in C:\Inetpub\wwwroot\msag\index.php on line 34

    Here is the index.php File:
    Code:
    <center><h1><u> MSAG Database </u></h1>
    <br>			
    <br>
    		
    <?php include 'includes/menu.php'; ?>
    			
    <form method="post" action="index.php">
    <input type="hidden" name="submitted" value="true" />
    
    <label>Search Category:
    
    <select name="category">
    	<option value="StreetName">Street Name</option>
    </select>
    </label>
    
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label>Search Criteria: <input type="text" name="criteria" /></label>
    
    <input type="submit" name="search" value="Search"/>
    
    </form>
    
    </center>
    <?php
    
    include 'includes/db/connect.php';
    
    if(isset($_POST['search']) || isset($_POST['submit']))
    {	 
    	$category = $_POST['category'];
    	$criteria = $_POST['criteria'];
    	
    	$query = "SELECT * FROM MSAG WHERE $category LIKE %$criteria% ORDER BY StreetName ASC";
    	$resource=sqlsrv_query($query);
    }	
    ?>
    <form action="" method="post">
    		<table align="center" border="1" cellpadding="2" cellspacing="2" width="100%" >
    		<tr align = 'center'>
    			<td><b>Street Name</b></td>
    		</tr>
    <?php
    while($result=sqlsrv_fetch_array($resource))
    { 
    	echo "
    <tr align = center>
    <td>".$result['StreetName']."</td>
    <td><a href=\"modify2.php?id=".$result['StreetID']."\"><input type=\"button\" name = \"details\" value = \"Details\" /></a></td>
    </tr>
    "; 		
    }
    ?>
    </table>
    </form>
    Ultimately I would like to be able to have several different drop boxes and text fields to search by. I thank you all in advance for your time and help.

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,627
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    The error message tells you exactly what's wrong:
    Code:
    Warning: sqlsrv_query() expects at least 2 parameters, 1 given in ...
    sqlsrv_query() expects the first argument to be a database connection (this is the arg you are missing), and the second argument to be the SQL query.
    We Only Torture the Folks We Don't Like (You're Probably Gonna Be Okay)
    It's a Party in the CIA

Similar Threads

  1. Replies: 2
    Last Post: 05-06-2011, 08:24 AM
  2. Replies: 1
    Last Post: 01-28-2011, 02:39 AM
  3. Replies: 2
    Last Post: 02-12-2010, 08:53 AM
  4. Customize the Error Object in JavaScript (Error Handler Script)
    By hari.gomatum in forum Submit a DHTML or CSS code
    Replies: 1
    Last Post: 12-13-2007, 05:56 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •