Hi,

I'm trying to query a database to pull out all results from the database where the location and server responsible are selected from a form on a previous page which are then posted over.

I can manage to post the selections from the form, but when it attempts to query the database for the selected values i get the following error message:

PHP Fatal error: Call to undefined function odbc_results() in D:\web\tivicheck\getinfo.php on line 21

Can anyone tell me why it is doing this?
I'm sure that odbc_results() is defined as i have to use it in the previous page to get the list of names to select to perform the query on the next page once you've selected one.

The code for the page is as follows:

<?php
$conn=odbc_connect('backuplogs','','');

if (!$conn)

{exit("Connection Failed: " . $conn);}

$postlocation = $_POST["t1"];
$postresponsible = $_POST["t2"];



$results="SELECT * FROM BackupLog WHERE 
Location = '$postlocation' 
AND Responsible = '$postresponsible'";

$rs=odbc_exec($conn, $results);

while (odbc_fetch_row($rs))
{
$location=odbc_results($rs, "Location");
$responsible=odbc_results($rs, "Responsible");

echo $location;
echo $responsible;
}

odbc_close($conn);
?>

Why not put your function(s) in a seperate file, and include that file as you need it

File1.php

function stuff()
{
     // do some stuff...
}

File2.php

include('File1.php');
$location=stuff();
echo $location;

I dont think that will help with the problem, I think its to do with the query itself. also if i remove the single quotes around $postlocation or $postresponsible i get a different error message:

PHP Warning: odbc_exec(): SQL error: [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'Location = Si AND Responsible = Windows / VMware Operation'., SQL state 37000 in SQLExecDirect in D:\web\tivicheck\getinfo.php on line 16 PHP Warning: odbc_fetch_row() expects parameter 1 to be resource, boolean given in D:\web\tivicheck\getinfo.php on line 18

Ohhhh apologies. I see what you're doing now...

Shouldn't it be odbc_result() instead of odbc_results() ?

Also leave the single quotes around the variables in your query otherwise mysql will enter them literally

yeah i just realized this now. thanks for pointing that out. I've been sitting here for nearly an hour trying to work it out and then it just hit me haha.

Thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.