Valhalla Legends Forums Archive | Web Development | [resolved] can't find function in include file (php5)

AuthorMessageTime
K
I'm absolutely stumped by this.

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

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
[/code]

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

[code]
<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
[/code]

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
[/quote]

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?
October 10, 2006, 8:24 PM
rabbit
<?php ?>
October 10, 2006, 8:40 PM
K
[quote author=rabbit link=topic=15850.msg159639#msg159639 date=1160512855]
<?php ?>
[/quote]

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.
October 10, 2006, 8:41 PM
K
Turns out I'm just dumb.  I was modifying "util.php" which I had copied to "util.php.inc" earlier.

Gah.
October 10, 2006, 8:54 PM
rabbit
[quote author=K link=topic=15850.msg159640#msg159640 date=1160512918]
[quote author=rabbit link=topic=15850.msg159639#msg159639 date=1160512855]
<?php ?>
[/quote]

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.
[/quote]You didn't show them (in the include), and I've been known to do it..so I figured...

[quote author=K link=topic=15850.msg159641#msg159641 date=1160513669]
Turns out I'm just dumb.  I was modifying "util.php" which I had copied to "util.php.inc" earlier.

Gah.
[/quote]I've done that too.
October 11, 2006, 12:14 AM
warz
PHP. :-X
October 11, 2006, 1:10 AM

Search