473,406 Members | 2,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 5831
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

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

Similar topics

9
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...
69
by: markarichman | last post by:
Why is Firefox complaining with this error: ------------------------------------------------------------ missing ) after argument list setTimeout('breakOut',5000);...
1
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...
0
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,...
2
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....
7
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>...
3
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. }...
2
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:...
7
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...
9
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",
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.