如果条件,则来自else的服务器错

时间:2012-07-24 02:14:35

标签: php

我一直收到服务器错误,我将其限制在此代码块中。我一定不熟悉语法。有人能指出为什么我收到服务器错误?我发布了所有代码。这就是.....

<?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 个答案:

答案 0 :(得分:4)

如果此代码不在循环内,则break是错误。

答案 1 :(得分:2)

您的代码很好,只需取出break;

即可

要打破循环,请将break;放在所有if语句的末尾。