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

Posted on 2005-04-06
Last Modified: 2013-12-13
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);

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!
Question by:MedtronicVascSR
    LVL 32

    Accepted Solution

    odbc_close is a function, not a variable. ( ). Remove the $ symbol from that line.
    LVL 8

    Assisted Solution

    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.

    Author Comment

    Thanks for the thoroughness of your answer Marcel - both of you were right so I will split points.
    LVL 32

    Expert Comment


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
    Both Easy and Powerful How easy is PHP? (  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now