-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>
4

2 回答 2

4

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

于 2012-07-24T02:17:27.730 回答
2

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

要中断循环,请将其放在break;所有 if 语句的末尾。

于 2012-07-24T02:16:36.763 回答