2010-05-01 64 views
0
/* Errors exist, have user correct them */ 
    if($form->num_errors > 0) 
    { 
     return 1; //Errors with form 
    } 
    /* No errors, add the new account to the */ 
    else if($database->addLeagueInformation($subname, $subformat, $subgame, $subseason, $subwindow, $subadmin, $subchampion, $subtype)) 
    { 
     $database->addLeagueTable(); 
     $_SESSION['players'] == $subplayers; 
     $comp_name == '$format_$game_$name_$season'; 
     $_SESSION['comp_name'] == $comp_name; 
     return 0; //New user added succesfully 
    } 
    else 
    { 
     return 2; //Registration attempt failed 
    } 

這是沒有做這些事情的時刻:構建一個如果,如果別的,else語句

$database->addLeagueTable(); 
    $_SESSION['players'] == $subplayers; 
    $comp_name == '$format_$game_$name_$season'; 
    $_SESSION['comp_name'] == $comp_name; 

有沒有更好的方式來做到這一點?

編輯!

$comp_name = "$subformat_$subgame_$subname_$subseason"; 
     $_SESSION['comp_name'] = $comp_name; 

這段代碼只會在$ subseason中產生什麼? 這是否有明顯的原因?

進一步編輯!

else if($database->addLeagueInformation($subname, $subformat, $subgame, $subseason, $subwindow, $subadmin, $subchampion, $subtype)) 
    { 
     $_SESSION['players'] = $subplayers; 
     $comp_name = "$subformat_$subgame_$subname_$subseason"; 
     $_SESSION['comp_name'] = $comp_name; 
     $database->addLeagueTable(); 
     return 0; //New user added succesfully 
    } 

和函數addLeagueTable()

function addLeagueTable() { 
    $q = "CREATE TABLE `$_SESSION[comp_name]` (
    `user` VARCHAR(30) NOT NULL , 
     `team` VARCHAR(40) NOT NULL , 
     `home_games_played` INT(3) NULL DEFAULT '0', 
     `home_wins` INT(3) NULL DEFAULT '0', 
     `home_draws` INT(3) NULL DEFAULT '0', 
     `home_losses` INT(3) NULL DEFAULT '0', 
     `home_points` INT(3) NULL DEFAULT '0', 
     `home_goals_for` INT(3) NULL DEFAULT '0', 
     `home_goals_against` INT(3) NULL DEFAULT '0', 
     `away_games_played` INT(3) NULL DEFAULT '0', 
     `away_wins` INT(3) NULL DEFAULT '0', 
     `away_draws` INT(3) NULL DEFAULT '0', 
     `away_losses` INT(3) NULL DEFAULT '0', 
     `away_points` INT(3) NULL DEFAULT '0', 
     `away_goals_for` INT(3) NULL DEFAULT '0', 
     `away_goals_against` INT(3) NULL DEFAULT '0' 
     )"; 
    return mysql_query($q, $this->connection); 
} 

什麼想法?

我是怎麼過..

 $retval = $session->createLeague($_POST['name'], $_POST['players'], $_POST['format'], $_POST['game'], $_POST['season'], $_POST['window'], $_POST['admin'], $_POST['champion'], $_POST['type']); 

這將它們發送給addLeagueInformation發送到功能!

回答

5

==是比較運算符,但是例如,在$_SESSION['players'] == $subplayers;中,您希望賦值運算符=
也許您還有一個問題$comp_name == '$format_$game_$name_$season';。在單引號字符串中,php不會替代變量。

+0

以下幾行同樣如此 – 2010-05-01 20:18:50

1

有沒有更好的方法來做到這一點?

其實執行任務?

$_SESSION['players'] = $subplayers; 
// ------------------^ one '=' instead of two '==' (which is for comparison). 
$comp_name = "{$format}_{$game}_{$name}_{$season}"; 
// double quotes to allow substitution, 
// {...} to avoid interpreting the variable name as `$format_`. 
$_SESSION['comp_name'] = $comp_name; 

並確保addLeagueInformation真的在您的測試返回非錯誤值,如果你希望他們被執行。

+0

這有幫助,但我不認爲$ comp_name ='$ format_ $ game_ $ name_ $ season'; 正在工作嗎? – sark9012 2010-05-01 20:25:31

+0

@Luke:你需要雙引號。 – kennytm 2010-05-01 20:27:04

+0

它使表格$ format_ $ game_ $ name_ $季節名稱。 – sark9012 2010-05-01 20:28:04