2012-07-24 78 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