Current location: Hot Scripts Forums » Programming Languages » PHP » string for odbc_fetch_array() help


string for odbc_fetch_array() help

Reply
  #1 (permalink)  
Old 06-29-07, 10:35 AM
sharijl's Avatar
sharijl sharijl is offline
Newbie Coder
 
Join Date: Nov 2005
Location: North Carolina
Posts: 86
Thanks: 1
Thanked 1 Time in 1 Post
string for odbc_fetch_array() help

constructing search page and using PHP odbc to connect and query Microsoft SQL. I have my connection but the search string is not working. What am I doing wrong here?

PHP Code:

<?php 


if (!isset($_POST['submit'])) 
{
            
  
//Collect Form Data
                        
  
$string $_POST['location'];
                        
  
//Establish data connection
                        
  
$database "dbname"
  
$odbc odbc_connect($database,"user","password");
                        
  
//Issue SQL SELECT Statement
                        
  
$sql "SELECT * FROM tablename WHERE location = '$string'";
                        
  
$rs odbc_exec($odbc$sql);
            }

?>


<!DOCTYPE html PUBLIC "-//W3C/DTD/XHTML 1.0 Transitional//EN"
            "http://www.w3.org/TR/xhtml1/DTD/xhtml11-transitional.dtd">
            
            
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>search</title>

<style>
  
  body {margin:15px;font:10pt Verdana}
  td {vertical-align:top;border:solid 1px gray}
  input,textarea{border:0px}
  
  </style>
  
 </head>
 
 <body>
 
 <form action="Search.php" method="post">
 <p>&nbsp;</p>
 <table>
 <tr>
 <td colspan="2">&nbsp;</td>
 </tr>
 <td><input type="text" size="15" name="location"/></td>
   <td><input type="submit" value="Search" name="submit"/>
 </tr>
 </table>
 </form>
  
 <div>
 
 <?php
 
 
if(!empty($_REQUEST))
 {
            while(
$row odbc_fetch_array($rs)) 
            
            {
            
            echo 
"Name: " .$row['name'] . "  ";
            echo  
$row['comments'] . "<br/>";
            }
            
            
odbc_close($odbc);
 }          
 
?>
 
 </div>
 </body>
 </html>
error message points to:
PHP Code:

while($row odbc_fetch_array($rs)) 

as the problem but the issue is with
PHP Code:

$sql "SELECT * FROM tablename WHERE location = '$string'";

$string $_POST['location']; 
because the connection is good.

Here is the exact error message I am concerned with:

PHP Code:

Warningodbc_fetch_array(): supplied argument is not a valid ODBC result resource in E:\Inetpub\wwwroot\Search.php on line 63


Warning
odbc_close(): supplied argument is not a valid ODBC-Link resource in E:\Inetpub\wwwroot\Search.php on line 71 

Last edited by sharijl; 06-29-07 at 10:38 AM.
Reply With Quote
  #2 (permalink)  
Old 06-29-07, 10:36 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Topic moved to database.
Reply With Quote
  #3 (permalink)  
Old 06-29-07, 10:40 AM
sharijl's Avatar
sharijl sharijl is offline
Newbie Coder
 
Join Date: Nov 2005
Location: North Carolina
Posts: 86
Thanks: 1
Thanked 1 Time in 1 Post
Don't think this is db issue because I can run the same query directly in SQL and it works fine. I think I need help with the PHP string? What do you think?
Reply With Quote
  #4 (permalink)  
Old 06-29-07, 10:49 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
The errors you get are from ODBC. Plus you posted this in ASP, so I felt like moving it.
Reply With Quote
  #5 (permalink)  
Old 06-29-07, 11:05 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
to debug your code, add odbc_errormsg() after each odbc_exec call:
PHP Code:

$rs odbc_exec $odbc$sql ) or die ( odbc_errormsg() ); 

and tell us what the outcome is

more information on odbc_errormsg:
http://be2.php.net/manual/en/function.odbc-errormsg.php
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #6 (permalink)  
Old 06-29-07, 04:29 PM
sharijl's Avatar
sharijl sharijl is offline
Newbie Coder
 
Join Date: Nov 2005
Location: North Carolina
Posts: 86
Thanks: 1
Thanked 1 Time in 1 Post
Oh .... I understand -- sorry about putting in ASP (thought it was in PHP)

The outcome was this error:

Undefined variable: rs
Undefined variable: odbc

I know the odbc is my connection and rs is the result of the connection and the string. I think I have the search string wrong. The input entered should the string value.
Reply With Quote
  #7 (permalink)  
Old 06-30-07, 01:48 PM
jfulton's Avatar
jfulton jfulton is offline
Community VIP
 
Join Date: Apr 2006
Location: Los Angeles, CA
Posts: 660
Thanks: 0
Thanked 0 Times in 0 Posts
Are you actually getting a successful connection to the database with the odbc_connect() call?

Oh, and moving to php .
Reply With Quote
  #8 (permalink)  
Old 06-30-07, 03:53 PM
sharijl's Avatar
sharijl sharijl is offline
Newbie Coder
 
Join Date: Nov 2005
Location: North Carolina
Posts: 86
Thanks: 1
Thanked 1 Time in 1 Post
db connections are correct.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
problem returning interest in bankaccount program psi3000 Everything Java 6 03-27-06 01:14 PM
BankAccount object oreinted help psi3000 Everything Java 6 03-16-06 10:07 AM
help to turn a filelist in to a winamp playlist mike-wigan Windows .NET Programming 0 10-18-05 11:10 AM
Declared Functions skipper23 PHP 4 12-17-03 10:06 AM
index page not showing up skipper23 PHP 3 12-15-03 01:10 PM


All times are GMT -5. The time now is 06:07 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.