Hey people
I'm slowly but surely getting there ..
This script is to check an input field that asks for a name of a pool league.
It is meant to check for leagues with the same name, and if one is found, show the name of the duplicate league and then give the option to edit it - instead of creating a duplicate. If one of the same name isn't found then check_duplicate returns FALSE and the new league is added.
HOWEVER ...
It does't work. Hehe.
I get the following errors ..
Notice: Undefined variable: row_leagues in C:\Websites\maccpoolleague\leagues_ex.php on line 159
Notice: Undefined variable: row_leagues in C:\Websites\maccpoolleague\leagues_ex.php on line 159
Notice: Undefined variable: row_leagues in C:\Websites\maccpoolleague\leagues_ex.php on line 160
Here's the function:
function check_duplicate(){
$query_leagues = mysql_query("SELECT id AS id, name AS name, format AS format FROM leagues"); // open connection.
if (mysql_num_rows($query_leagues) > 0) { // only run the check if there is one or more leagues.
while ($row_leagues = mysql_fetch_array($query_leagues)) { // start streaming the leagues.
if (strtoupper(trim($_POST['name'])) == $row_leagues['name'] && $_POST['format'] == $row_leagues['format']) { // look for a match of league names and format.
return ($row_leagues); // if found, finish function and return array - $row_leagues ['name'], ['id'] and ['format']
}
}
return false; // if, after streaming the leagues, none are found that match the input then return false.
} else {
return false; // ditto for no leagues already in database, as it doesn't need to check.
}
}
And here's the function call:
if (check_duplicate()) { // is it TRUE, uh OH ! YES! Better make them aware!
echo '<b>Error:</b> There is already a league with that name and format: <br />' . $row_leagues['name'] . ' (' . $row_leagues['format'] . ')';
echo ' [ <a href="' . $_SERVER['PHP_SELF'] . '?action=edit&league_id=' . $row_leagues['id'] . '">EDIT THIS LEAGUE</a> ]';
} else { // It's FALSE then so add it.
add_league();
};
Thanks for your help in advance
- Alex