Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Lau
    Lau is offline
    New Coder
    Join Date
    Jan 2004
    Location
    Malden, MA
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem with require & Fatal error: Call to undefined function

    Hey Everyone,

    I've been looking at that piece of code for so long that I'm sure I'm overlooking something.
    I have two php files, one called "display_main.php", the second one is "display_category.php"
    there is a require("display_category.php"); in the first file, and one function is called from this. I've checked spelling a million times, and I really don't think that where the probleme is. I need someone with a fresh eye to tell me what I can't see obvisouly
    PHP Code:
    <?php

      
    // requires
      
    require("utils.php");
      require(
    "display_category.php");
      
    //require("games.php");

      // Connects to the database and checks for good connection
      
    $dbLink connectToCat();
      if (
    $dbLink == 0)
        die (
    "Error: Could not Connect to Database");

      
    // gets category name from URL
      
    $cat $_GET['cat'];

      if ( 
    strlen($cat) > 0) {
        echo 
    "<html> <body>";
        echo 
    "<table width=100% border=3 cellpadding=5 cellspacing=5>";
        
    display($dbLink$cat);
      } else
        echo 
    "You did not make a valid choice";

      echo 
    "<form method='link' action='index_proj4.html'>";
      echo 
    "<br> <input type='submit' value='Back'> </form>";

      
    //closes table and body from the corresponding call
      
    echo "</table>";
      echo 
    "</body></html>";

      
    mysql_close($dbLink);

    ?>
    PHP Code:
    <?php

    // display the info from the correct table according
    // to category selected in index_proj4.html page

    function display($dbLink$cat) {

      
    /*********************************/
      /* display from VIDEO_GAME table */
      /*********************************/
      
    if ($cat == 'game') {

        
    $select "SELECT * FROM VIDEO_GAME";
        
    $query mysql_query($select$dbLink);

        
    // headers
        
    echo "<tr> <td> </td>
            <td> Name </td>
            <td> Manufacturer </td>
            <td> Type </td>
            <td> Overall <br> Rating </td>
            <td> Gameplay <br> Rating </td>
            <td> Graphics <br> Rating </td>
            <td> Sound <br> Rating </td>
            <td> Price ($) </td>
            <td colspan=2 align=center> Reviews </td> </tr>"
    ;

        
    //display SELECT * FROM VIDEO_GAME query
        
    while ($row mysql_fetch_array($query)) {

          
    // grabs the 4 different average ratings into $rating
          
    $name $row['name'];

          
    $average "SELECT AVG(overall) as overall, AVG(gameplay) as gameplay, AVG(graphics) as graphics, AVG(sound)
    as sound FROM VIDEO_GAME_DETAIL WHERE name = '$name'"
    ;

          
    $result mysql_query($average) or die('ERROR: could not run query');;

          if (
    mysql_num_rows($resultavg) == 0)
            echo 
    "No rows returned";
          elseif (
    mysql_num_rows($result) == 1){
            
    $rating mysql_fetch_array($result);

          echo 
    "<tr valign=middle> <td align=center> <img src=games/" .$row['pic']. "></td>";
          echo 
    "<td>" .$row['name']. "</td>";
          echo 
    "<td>" .$row['manufacturer']. "</td>";
          echo 
    "<td>" .$row['type']. "</td>";
          echo 
    "<td>" .$rating['overall']. "</td>";
          echo 
    "<td>" .$rating['gameplay']. "</td>";
          echo 
    "<td>" .$rating['graphics']. "</td>";
          echo 
    "<td>" .$rating['sound']. "</td>";
          echo 
    "<td>" .$row['price']. "</td>";
          echo 
    "<td> <a href='read.php?name=" .$row['name']. "'>
                     <input type='button' name='read' value='Read'> </a> </td>"
    ;
          echo 
    "<td> <a href='write.php?name=" .$row['name']. "'>
                     <input type='button' name='write' value='Write'> </a> </td> </tr>"
    ;
        }
      }
      
    /*********************************/
      /* display from CELL_PHONE table */
      /*********************************/
      
    elseif ($cat == 'cell') {
        
    $select "SELECT * FROM CELL_PHONE";
        
    $query mysql_query($select$dbLink);

        
    // headers
        
    echo "<tr> <td> </td>
            <tr> <td> </td>
            <td> Name </td>
            <td> Manufacturer </td>
            <td> Price ($) </td>
            <td colspan=2 align=center> Reviews </td> </tr>"
    ;

        while (
    $row mysql_fetch_array($query)) {

          echo 
    "<tr> <td align=center> <img src=cell/" .$row['pic']. "></td>";
          echo 
    "<td>" .$row['name']. "</td>";
          echo 
    "<td>" .$row['manufacturer']. "</td>";
          echo 
    "<td>" .$row['price']. "</td>";
          echo 
    "<td> <a href='read.php?cell=" .$row['name']. "'>
                     <input type='button' name='read' value='Read'> </a> </td>"
    ;
          echo 
    "<td> <a href='write.php'> <input type='button' name='write' value='Write'> </a></td> </tr>";
        }
      }
    }
    this function doesn't stop there, but the rest is repeating.

    Anyone can tell me why I'm getting the Fatal Error??????

    My second problem is with the elseif statement, where I get a parse error... I'm clueless here again!! It actually used to work, not anymore though!

    Anyone...?

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Which elseif are you talking about?

  • #3
    Lau
    Lau is offline
    New Coder
    Join Date
    Jan 2004
    Location
    Malden, MA
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts
    alright then!!

  • #4
    Regular Coder
    Join Date
    Mar 2004
    Posts
    115
    Thanks
    0
    Thanked 0 Times in 0 Posts
    added comment where i think elseif is causing problem


    PHP Code:
     while ($row mysql_fetch_array($query)) { 

          
    // grabs the 4 different average ratings into $rating 
          
    $name $row['name']; 

          
    $average "SELECT AVG(overall) as overall, AVG(gameplay) as gameplay, AVG(graphics) as graphics, AVG(sound) 
    as sound FROM VIDEO_GAME_DETAIL WHERE name = '$name'"


          
    $result mysql_query($average) or die('ERROR: could not run query');; 

          if (
    mysql_num_rows($resultavg) == 0
            echo 
    "No rows returned"
          elseif (
    mysql_num_rows($result) == 1){ 
            
    $rating mysql_fetch_array($result); 

          echo 
    "<tr valign=middle> <td align=center> <img src=games/" .$row['pic']. "></td>"
          echo 
    "<td>" .$row['name']. "</td>"
          echo 
    "<td>" .$row['manufacturer']. "</td>"
          echo 
    "<td>" .$row['type']. "</td>"
          echo 
    "<td>" .$rating['overall']. "</td>"
          echo 
    "<td>" .$rating['gameplay']. "</td>"
          echo 
    "<td>" .$rating['graphics']. "</td>"
          echo 
    "<td>" .$rating['sound']. "</td>"
          echo 
    "<td>" .$row['price']. "</td>"
          echo 
    "<td> <a href='read.php?name=" .$row['name']. "'> 
                     <input type='button' name='read' value='Read'> </a> </td>"

          echo 
    "<td> <a href='write.php?name=" .$row['name']. "'> 
                     <input type='button' name='write' value='Write'> </a> </td> </tr>"

        } 
      } 
      
    /*********************************/ 
      /* display from CELL_PHONE table */ 
      /*********************************/ 
      
    elseif ($cat == 'cell') { // ibelieve this else if is following the while at top so should be an if
        
    $select "SELECT * FROM CELL_PHONE"
        
    $query mysql_query($select$dbLink); 

  • #5
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It would be helpfill if you print the exact erromessage, including the line it occurs on, and then place a comment or so on that line...

    I see you have copied some code from a thread in the mySQL forum, but that you made some errors while modifying it
    PHP Code:
    if (mysql_num_rows($resultavg) == 0
    // the $resultavg --> read my comment on alsays using a unique name for your queryresult. You edited it back to $result except in the line above. Bad codingattitude bu don't let me stop you
            
    echo "No rows returned";  
          elseif (
    mysql_num_rows($result) == 1){  
    /* hello, 
    if()
    elseif {
    ???
    Check the code you copied from.
    The 
    if() could very well be interpreted as function 'if()' which could explain your error
    */
            
    $rating mysql_fetch_array($result); 
    Maybe first fix you cut and past and customization-error and then get back to us with a clear errordescription + the complete errormessages + the completecode where you clearly marked the lines where the error occurs on.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #6
    Lau
    Lau is offline
    New Coder
    Join Date
    Jan 2004
    Location
    Malden, MA
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sidney - it just doesn't get any stupider than that!!!
    There was an extra '{'... Thank you for your observation skills...

    Raf - I cahnged the name to $result, not resultavg (<-that would have been how I called it before, and didn't bother to change that one when I changed all the other ones!!)
    Thank you to you too...

    -------------------------------------

    I have another quick question.
    In the above code, I wrote:
    PHP Code:
    echo "<tr> <td> </td> 
            <td> Name </td> 
            <td> Manufacturer </td> 
            <td> Type </td> 
            <td> Overall <br> Rating </td> 
            <td> Gameplay <br> Rating </td> 
            <td> Graphics <br> Rating </td> 
            <td> Sound <br> Rating </td> 
            <td> Price ($) </td> 
            <td colspan=2 align=center> Reviews </td> </tr>"

    Would you guys recommend that? or should I start another echo "..." at each newline?
    Last edited by Lau; 04-01-2004 at 04:13 PM.

  • #7
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You don't need a new echo for each line no. But i would use
    PHP Code:
    echo '<tr> <td> </td> 
            <td> Name </td> 
            <td> Manufacturer </td> 
            <td> Type </td> 
            <td> Overall <br> Rating </td> 
            <td> Gameplay <br> Rating </td> 
            <td> Graphics <br> Rating </td> 
            <td> Sound <br> Rating </td> 
            <td> Price ($) </td> 
            <td colspan="2" align="center"> Reviews </td> </tr>'

    Because the text between single quotes isn't parsed (look at the colourcoding for the $) and you can then use valid xhtml syntax without adding slashes

    About your previous problem:
    the
    if()
    elseif{
    }
    is realy wrong. I can not imagen that this doesn't error on you
    Last edited by raf; 04-01-2004 at 09:12 PM.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #8
    Lau
    Lau is offline
    New Coder
    Join Date
    Jan 2004
    Location
    Malden, MA
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you, I'm taking notes of what you said.

    About your previous problem:
    the
    if()
    elseif{
    }
    is realy wrong. I can not imagen that this doesn't error on you
    I did fix that...
    PHP Code:
          if (mysql_num_rows($result) == 0)
            echo 
    "No rows returned";
          else
            
    $rating mysql_fetch_array($result); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •