472,358 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,358 software developers and data experts.

Argument is not a valid MS SQL-result resource

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>
  11. <?php
  12.     $reference = $_POST['searchref'];
  13.     $query = "SELECT AmberCatRequestId ";
  14.     $query.= "FROM Customer_Calls ";
  15.     $query.= "WHERE CustomerCallId = $reference";
  17.     $result = mssql_query($query);
  18.     if($row = mssql_fetch_object($result))
  19.     {
  20.         $ref = $row->AmberCatRequestId;
  21.     }
  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>
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 5744
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";
  6. $result = mssql_query($query);
  7. if($row = mssql_fetch_object($result))
  8. {
  9. $ref = $row->AmberCatRequestId;
  10. }
  12. ?>
your PHP code start with the line
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.

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
thanks jpr0325, this is exactly what i was looking for
Mar 9 '10 #5

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

Similar topics

by: subdhar | last post by:
I'm getting following error in asp.net application.I search the web and couldn't find error like this can any one help me in trouble with this error Specified argument was out of the range of...
by: markarichman | last post by:
Why is Firefox complaining with this error: ------------------------------------------------------------ missing ) after argument list setTimeout('breakOut',5000);...
by: Timbo | last post by:
Hi all, This is my first message here so i'll try and include all the information that will help you help me out, if possible. Basically I am using C# in ASP.NET 2.0 and have a Repeater...
by: Subhankar | last post by:
Hi, I am trying to open a MS Project residing in a MS SQL Server. I have the following code for the FileOpen: projectApp.FileOpen("<ChouOister>\\Test Project 2", false, 0, null, null, null,...
by: Nathan Sokalski | last post by:
I have a DataList in which the ItemTemplate contains two Button controls that use EventBubbling. When I click either of them I receive the following error: Server Error in '/' Application....
by: bowlderster | last post by:
Hello,all. I want to get the array size in a function, and the array is an argument of the function. I try the following code. /*************************************** */ #include<stdio.h>...
by: linarin | last post by:
#include <iostream> using namespace std; typedef bool (*CallableFunction)(int argc,char* argv); void DefineMyFunction(const char* name,CallableFunction func){ //here do the define action. }...
by: Chapi | last post by:
hi, i'm having problems with a datagrid paging. it's populates fine, but when i click the paging button appears this error:"Specified argument was out of the range of valid values.Parameter name:...
by: mirandacascade | last post by:
The questions are toward the bottom of this post. Situation is this: 1) Access 97 2) Multi-user appplication 3) SQL Server 2000 4) Sporadically (i.e. less than 1% of the time) encounter the...
by: 200dogz | last post by:
Hi guys, I want to have a button which opens up a new window when pressed. <asp:Button ID="Button1" runat="server" Text="Open new window" /> ... Button1.Attributes.Add("OnClick",
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.