2012-07-24 51 views
-1

我不斷收到服務器錯誤,我已經限制它到這個代碼塊。我不能熟悉語法。有人可以指出爲什麼我得到一個服務器錯誤?我發佈了所有的代碼。這.....服務器錯誤從其他條件如果條件

<?php 
// this starts the session 
session_start(); 
$id = $_SESSION['userid']; 

//this connects to the database 
$con = mysql_connect("example","example","example"); 
mysql_select_db("example", $con); 

//this is the info the user entered stored as variables 
$leaguename = $_POST["leaguename"]; 
$members = $_POST["members"]; 
$leaguepassword = $_POST["leaguepassword"]; 

    //this filters throught the variables to check against mysql injections 
$leaguename = (filter_var($leaguename, FILTER_SANITIZE_STRING)); 
$leaguename = (filter_var($leaguename, FILTER_SANITIZE_URL)); 
$members = (filter_var($members, FILTER_SANITIZE_STRING)); 
$members = (filter_var($members, FILTER_SANITIZE_URL)); 
$leaguepassword = (filter_var($leaguepassword, FILTER_SANITIZE_STRING)); 
$leaguepassword = (filter_var($leaguepassword, FILTER_SANITIZE_URL)); 

//this is the variables that displays errors 
$errors = ""; 
$result = mysql_query("SELECT * FROM League_Info WHERE League = '$leaguename'"); 
$result2 = mysql_fetch_array($result); 
$result3 = $result2['League']; 

$result4 = mysql_query("SELECT * FROM League_Info WHERE User_ID = '$id'"); 
$result5 = mysql_fetch_array($result4); 
$result6 = $result5['User_ID']; 

if ($id == "") { 
    $errors .= "<li>You must register or login to create a league!"; break; 
    } elseif ($result3 != "") { 
    $errors .= "<li>League Name already in use!"; break; 
    } elseif ($result6 != "") { 
    $errors .= "<li>You already have a league!"; break; 
    } else { 
} 

// no errors 
if ($errors == "") { 
    $sql="INSERT INTO League_Info (League, User_ID, Commissioner, Year, Members, League_Password) 
     VALUES('$leaguename', '$id', 'y', '2012', '$members', '$leaguepassword')"; 
    mysql_query($sql); 
     /* Redirect browser */ 
    header("Location: http://www.yourfantasyfootballreality.com/invite.php"); 
    /* Make sure that code below does not get executed when we redirect. */ 
    exit; 

} else { 
} 

?> 

<html><head><title>Create a League</title></head> 

<body> 

<center><h1>Create a League</h1></center> 

<center> 
<div class="form" style= "width:500px; height:200px; background-color:gray; "> 
<form action="createleaguevalidation.php" method="POST"> 
League Name:  <input style="margin-left:0px;" type="text" name="leaguename" value="<?=$leaguename?>" /><br /> 
Number of Members: <input type="text" name="members" value="<?=$members?>"/><br> 
League Password: <input type="password" name="leaguepassword" value="<?=$leaguepassword?>"><br> 
<input type="submit" value="Create League" name="action"> 
<input type="reset" value="Reset"> 
</form> 

<div style="background-color:#ffcccc; height:80px; width:500px;"> 
<?=$errors?> 
</div> 

</div> 
<center> 

</body> 
</html> 
+2

um ..什麼錯誤? – tradyblix 2012-07-24 02:15:29

+0

如果包含收到的實際錯誤,我們將能夠更好地爲您提供幫助。 – 2012-07-24 02:17:55

+0

HTTP錯誤500(內部服務器錯誤):服務器嘗試完成請求時遇到意外情況。 – 2012-07-24 02:18:53

回答

4

如果此代碼不在循環內,則break是錯誤。

+0

那麼我會如何退出,當它滿足給定條件? – 2012-07-24 02:18:18

+0

@FaceBook:退出什麼?顯示更多代碼! – 2012-07-24 02:18:53

+0

這是我所有的相關代碼。應該把它放在一個循環中,但我不知道我會如何做到這一點 – 2012-07-24 02:20:51

2

你的代碼是正確的,只是拿出break;

爲了打破循環,把break;在所有的if語句的結束。

+0

但我想打破循環,如果它符合條件 – 2012-07-24 02:17:26

+2

使用die而不是 – 2012-07-24 02:17:52

+0

是如果在一個循環內的語句? – pat34515 2012-07-24 02:18:30