469,299 Members | 2,035 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,299 developers. It's quick & easy.

Argument is not a valid MS SQL-result resource

3
I am using a text box to search database for a reference number, the search is working ok but i am getting this error when i load the page for the first time:

Warning: mssql_fetch_object(): supplied argument is not a valid MS SQL-result resource in C:\Documents . . . on line 167

When i do a search i get the expected results and the error disappears

here is my code:
Expand|Select|Wrap|Line Numbers
  1. <form id="refsearch" name="searchRef" method="post">
  2.   <table>
  3.     <tr>
  4.       <td>Enter Call Ref</td>
  5.       <td><input name="searchref" type="text" class="textfield" id="searchref" /></td>
  6.     </tr>
  7.     <tr>
  8.       <td><input type="submit" name="search" value="Search" /></td>
  9.     </tr>
  10.  
  11. <?php
  12.     $reference = $_POST['searchref'];
  13.     $query = "SELECT AmberCatRequestId ";
  14.     $query.= "FROM Customer_Calls ";
  15.     $query.= "WHERE CustomerCallId = $reference";
  16.  
  17.     $result = mssql_query($query);
  18.     if($row = mssql_fetch_object($result))
  19.     {
  20.         $ref = $row->AmberCatRequestId;
  21.     }
  22.  
  23. ?>
  24.     <tr>
  25.     <td><h4><br />AmberCat Request:&nbsp;</h1></td>
  26.     <td><h1><br /><?echo $ref;?></h4></td>
  27.     </tr>
  28.   </table>
  29. </form>
  30.  
how do i stopped the error from appearing when the page is first loaded?
Mar 8 '10 #1

✓ answered by jpr0325

First time when u load a page there won't be value set for $_POST['searchref'] so you query will be worng..

Check condition if $_POST['searchref'] is not equal to null and then execute the query part.

Hope this will help u...:)

4 5595
johny10151981
1,059 1GB
Can you please post your code in code format.

Expand|Select|Wrap|Line Numbers
  1. $reference = $_POST['searchref'];
  2. $query = "SELECT AmberCatRequestId ";
  3. $query.= "FROM Customer_Calls ";
  4. $query.= "WHERE CustomerCallId = $reference";
  5.  
  6. $result = mssql_query($query);
  7. if($row = mssql_fetch_object($result))
  8. {
  9. $ref = $row->AmberCatRequestId;
  10. }
  11.  
  12. ?>
your PHP code start with the line
$_POST['searchref']
but when you load your page for the first time there is no $_POST['searchref'] exists

take a closer look at isset() function. you would definitely get an error. so what you can do is first make sure
whether $_POST['searchref'] exists. If it exists perform rest of the operation otherwise skip it.

Regards,
Johny
Mar 8 '10 #2
First time when u load a page there won't be value set for $_POST['searchref'] so you query will be worng..

Check condition if $_POST['searchref'] is not equal to null and then execute the query part.

Hope this will help u...:)
Mar 8 '10 #3
JamieC
3
thanks jpr0325, this is exactly what i was looking for
Mar 9 '10 #5

Post your reply

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

Similar topics

69 posts views Thread by markarichman | last post: by
2 posts views Thread by Nathan Sokalski | last post: by
7 posts views Thread by mirandacascade | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.