[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 886
  • Last Modified:

PHP Undefined variable: odbc_close.... Fatal error: Function name must be a string....

The following code:

<table border="1">
<script language="php">
      $ds = odbc_connect("myTest", "", "");
      $shortlist = odbc_do($ds, "
            SELECT *
            FROM shortlist;
      ");
      while(odbc_fetch_row($shortlist)) {
            $lname = odbc_result($shortlist, 1);
            $fname = odbc_result($shortlist, 2);
            $email = odbc_result($shortlist, 3);
            print("
                  <tr>
                  <td>$fname</td>
                  <td>$lname</td>
                  <td>$email</td>
                  </tr>
            ");}
      $odbc_close($ds);
</script>
</table>

Gives me the following errors:
          Notice: Undefined variable: odbc_close in c:\webroot\myTest\index.php on line 26
          Fatal error: Function name must be a string in c:\webroot\myTest\index.php on line 26

If I omit odbc_close (comment it out), the code executes just fine.  But it doesn't solve the problem of the fact that the function is not performing the way I think it's supposed to.  Perhaps this is an installation issue?  I just installed PHP and am using on this machine for the first time - Windows XP Pro.


Thanks in advance!
Regards,
Carlos
0
MedtronicVascSR
Asked:
MedtronicVascSR
  • 2
2 Solutions
 
ldbkuttyCommented:
odbc_close is a function, not a variable. ( http://www.php.net/odbc_close ). Remove the $ symbol from that line.
0
 
_Marcel_Commented:
ldbkutty is completly right. Let me explain the errors to you:

Notice: Undefined variable: odbc_close in c:\webroot\myTest\index.php on line 26

This tells you that the variable $odbc_close is not defined, this is not a big deal, but for you it is a signal that you are using a variable that you probably want to set first, or made a typo (like this case!). The variable is now implicitly defined and set to a NULL value. This results in the next error:

Fatal error: Function name must be a string in c:\webroot\myTest\index.php on line 26

PHP has the ability to use variable functions, and so you are allowed to use a variable as a functionname. In your case, this is the variable $odbc_close, with the value NULL. This value is now used as a functionname, but functionnames have to be a string (i.e. a word). PHP doesn't have a function with no name...

Hopefully this info would help you recognize the errors the next time.
0
 
MedtronicVascSRAuthor Commented:
Thanks for the thoroughness of your answer Marcel - both of you were right so I will split points.
Regards,
Carlos
0
 
ldbkuttyCommented:
:=)
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now