This code right here works perfectlly fine
This is tournament.class
Code: Select all
function AddTournament() {
$title = $_POSTї'name'];
$game = $_POSTї'game'];
$tourney = $DB->Query("INSERT INTO tournaments VALUES ('', '$title', '$game', '', '')");
if ($tourney) {
echo "Tournament has been added to the database";
}
else
{
echo "Tournament could not be added ". mysql_error();
}
}Code: Select all
function ViewTournaments() {
if (isset($_GETїid])) {
$id = $_GETїid];
//Line 40 -> $tourneys = $DB->Query("SELECT * FROM tournaments WHERE id='$id'");
$row = mysql_fetch_row($tourneys);
if ($row) {
$this->tournamentї'id'] = $rowї0];
$this->tournamentї'name'] = $rowї1];
$this->tournamentї'game'] = $rowї2];
$this->tournamentї'standings'] = $rowї3];
$this->tournamentї'winners'] = $rowї4];
}
else
{
echo "Query unsuccessful on line ". __LINE__ ." in ".__FILE__;
}
}
else
{
//Line 63 -> $tourneys = $DB->Query("SELECT * FROM tournaments ORDER BY id DESC");
if ($tourneys) {
while ($row = mysql_fetch_row($tourneys)) {
$this->tournamentї'id'] = $rowї0];
$this->tournamentї'name'] = $rowї1];
}
}
else
{
echo "Query unsuccesful on line ". __LINE__ ." in ". __FILE__;
}
}
return;
}Fatal error: Call to a member function on a non-object in /home/www/hunterhp.freeownhost.com/tournament.class on line 40" (If $_GET[id] is set) or it gives me a "
Fatal error: Call to a member function on a non-object in /home/www/hunterhp.freeownhost.com/tournament.class on line 63" if it's not.
I don't understand why this is happening. I used $DB->Query on the function above and it works perfectly, but not on ViewTournaments()
The tournament.class gets outputed on tournament.php, which I'll show the source here.
tournament.php
Code: Select all
<?php
// Tournament Script tournaments.php Created January 31, 2005 at 3:00 A.M.
include("config.inc");
include("tournament.class");
?>
<html>
<head>
<title>Tournament</title>
</head>
<body>
<?
$Render = new Tournament;
$Render->Template('tournament.html');
if (isset($_POSTїsubmit])) {
$Render->AddTournament();
}
$Render->ViewTournaments();
$Render->CreatePage();
?>
<form action='tournament.php' method='post'>
Title: <input type='text' name='name'><br>
Game: <input type='text' name='game'><br>
<input type='submit' name='submit' value='Submit'>
</body>
</html>