• Welcome to Valhalla Legends Archive.
 

[resolved] can't find function in include file (php5)

Started by K, October 10, 2006, 03:24 PM

Previous topic - Next topic

K

I'm absolutely stumped by this.

The file include/util.php.inc looks like this:


function get_player_name($pid)
{
   $db = mysql_connect('localhost', 'user', 'password');
   mysql_select_db('pongstats', $db);
   $result = mysql_query("SELECT name FROM players WHERE id=$pid");
   $row = mysql_fetch_assoc($result);
   return $row['name'];
}

function get_player_id($player_name)
{
   $db = mysql_connect('localhost', 'user', 'password');
   mysql_select_db('pongstats', $db);
   $result = mysql_query("SELECT id FROM players WHERE name='$player_name'");
   $row = mysql_fetch_assoc($result);
   return $row['id'];
}

// ... more stuff


The file viewplayer.php looks like this, as I want to be able to lookup players by name as well as id.


<html>
<head>
<title>test page</title>
<body>
<?php

include('./include/util.php.inc');


$player_name $_GET['name'];
$id $_GET['id'];


if (!
is_null($id))
{   
   
$player_name get_player_name($id);
}
else if (!
is_null($player_name))
{
   
$id get_player_id($player_name);
}
// more stuff


When I reference it like so: viewplayer.php?id=1 it works great.  But when I do this: viewplayer.php?name=Foo, it complains:

Quote
Fatal error: Call to undefined function get_player_id() in /home/ledbettj/projects/web/pongtracker/viewplayer.php on line 20

Now, if I copy and paste the function get_player_id($player_name) into viewplayer.php, it works great.

Why can it locate get_player_name, but not get_player_id?

rabbit

Grif: Yeah, and the people in the red states are mad because the people in the blue states are mean to them and want them to pay money for roads and schools instead of cool things like NASCAR and shotguns.  Also, there's something about ketchup in there.

K

Quote from: rabbit on October 10, 2006, 03:40 PM
<?php ?>

Not sure what you're getting at.  I have those tags in the include file (I also tried it without them with the same result).  I took them out of my post to avoid the terrible coloring that you see on the second code block.

K

Turns out I'm just dumb.  I was modifying "util.php" which I had copied to "util.php.inc" earlier.

Gah.

rabbit

Quote from: K on October 10, 2006, 03:41 PM
Quote from: rabbit on October 10, 2006, 03:40 PM
<?php ?>

Not sure what you're getting at.  I have those tags in the include file (I also tried it without them with the same result).  I took them out of my post to avoid the terrible coloring that you see on the second code block.
You didn't show them (in the include), and I've been known to do it..so I figured...

Quote from: K on October 10, 2006, 03:54 PM
Turns out I'm just dumb.  I was modifying "util.php" which I had copied to "util.php.inc" earlier.

Gah.
I've done that too.
Grif: Yeah, and the people in the red states are mad because the people in the blue states are mean to them and want them to pay money for roads and schools instead of cool things like NASCAR and shotguns.  Also, there's something about ketchup in there.