Results 1 to 2 of 2

Thread: sqlsrv_fetch_array() Error

  1. #1
    Join Date
    Oct 2011
    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:
    <center><h1><u> MSAG Database </u></h1>
    <?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>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label>Search Criteria: <input type="text" name="criteria" /></label>
    <input type="submit" name="search" value="Search"/>
    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";
    <form action="" method="post">
    		<table align="center" border="1" cellpadding="2" cellspacing="2" width="100%" >
    		<tr align = 'center'>
    			<td><b>Street Name</b></td>
    	echo "
    <tr align = center>
    <td><a href=\"modify2.php?id=".$result['StreetID']."\"><input type=\"button\" name = \"details\" value = \"Details\" /></a></td>
    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
    Thanked 516 Times in 502 Posts
    Blog Entries


    The error message tells you exactly what's wrong:
    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.

Similar Threads

  1. Replies: 2
    Last Post: 05-06-2011, 08:24 AM
  2. Replies: 1
    Last Post: 01-28-2011, 03:39 AM
  3. Replies: 2
    Last Post: 02-12-2010, 09: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, 06:56 AM


Posting Permissions

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