...

View Full Version : Problem with require & Fatal error: Call to undefined function



Lau
03-31-2004, 06:52 PM
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

// 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

// 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! :rolleyes:

Anyone...?

Nightfire
03-31-2004, 06:56 PM
Which elseif are you talking about?

Lau
03-31-2004, 06:58 PM
alright then!! :p

sidney
03-31-2004, 08:04 PM
added comment where i think elseif is causing problem



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);

raf
04-01-2004, 06:58 AM
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


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.

Lau
04-01-2004, 03:11 PM
Sidney - it just doesn't get any stupider than that!!!
There was an extra '{'... Thank you for your observation skills... :thumbsup:

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... :thumbsup:

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

I have another quick question.
In the above code, I wrote:

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?

raf
04-01-2004, 08:07 PM
You don't need a new echo for each line no. But i would use


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

Lau
04-02-2004, 12:05 AM
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...

if (mysql_num_rows($result) == 0)
echo "No rows returned";
else
$rating = mysql_fetch_array($result);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum