Hallo,

Ik heb de volgende pagina gemaakt, maar krijg de volgende error:
[13-Jul-2009 03:45:17] PHP Parse error: syntax error, unexpected '}' in C:\Program Files\Zend\Apache2\htdocs\register.php on line 7

Weet iemand hier raad mee? Bedankt zover!

<?php

require_once('Connections/Leagues.php');

//Check if user is already logged in
if(isset($_SESSION['USERID'])){header('location: msg.php?msg=alreadyloggedin')};

if($_SERVER['REQUEST_METHOD'] == 'POST'){
if(isset($_POST['submit'])){

//Convert Vars
$username = $_POST['username'];
$password = $_POST['password'];
$password1 = $_POST['password1'];
$email = $_POST['email'];
$email1 = $_POST['email1'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$age = $_POST['age'];
$gender = $_POST['gender'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$city = $_POST['city'];
$postelcode = $_POST['postelcode'];
$country = $_POST['country'];
$newsletter = $_POST['newsletter'];
$termsagreed = $_POST['termsagreed'];
$ip = $_SERVER['REMOTE_ADDR'];
$level = $_POST['level'];

//Check if required vars are filled
if(empty($username)){header('location: msg.php?msg=enterusername')};
if(empty($password)){header('location: msg.php?msg=enterpassword')};
if(empty($password1)){header('location: msg.php?msg=enterpassword1')};
if(empty($email)){header('location: msg.php?msg=enteremail')};
if(empty($email1)){header('location: msg.php?msg=enteremail1')};
if(empty($firstname)){header('location: msg.php?msg=enterfirstname')};
if(empty($lastname)){header('location: msg.php?msg=enterlastname')};
if(empty($age)){header('location: msg.php?msg=enterage')};
if(empty($gender)){header('location: msg.php?msg=entergender')};
if(empty($termsagreed)){header('location: msg.php?msg=entertermsagreed')};
if(empty($ip)){header('location: msg.php?msg=iperror')};

//Check if required vars have there lengt
if(strlen($username) > 4){header('location: msg.php?msg=usernameshort')};
if(strlen($password) > 4){header('location: msg.php?msg=passwordshort')};
if(strlen($password1) > 4){header('location: msg.php?msg=password1short')};
if(strlen($email) > 6){header('location: msg.php?msg=emailshort')};
if(strlen($email1) > 6){header('location: msg.php?msg=email1short')};
if(strlen($firstname) > 2){header('location: msg.php?msg=firstnameshort')};
if(strlen($lastname) > 2){header('location: msg.php?msg=lastnameshort')};

//Check if vars are confirmed
if($password != $password1){header('location: msg.php?msg=passwordnoconfirm')};
if($email != $email){header('location: msg.php?msg=emailnoconfirm')};

//Check if vars already exists
$result = mysql_result(mysql_query("SELECT COUNT(1) FROM users WHERE username = '$username'"),0);
if(!empty($resultaat)){header('location: msg.php?msg=usernameinuse')};
$result = mysql_result(mysql_query("SELECT COUNT(1) FROM users WHERE email = '$email'"),0);
if(!empty($resultaat)){header('location: msg.php?msg=emailinuse')};
$result = mysql_result(mysql_query("SELECT COUNT(1) FROM users WHERE ip = '$ip'"),0);
if(!empty($resultaat)){header('location: msg.php?msg=ipinuse')};

//Generate activation var
$actcode = mt_srand((double)microtime()*100000);
while(strlen($actcode) <= 10)
{
$i = chr(mt_rand(0,255));
if(eregi('^[a-z0-9]$', $i))
{
$actcode = $actcode.$i;
}
}

//Var insert query
rquery = "INSERT INTO users (username, password, email, firstname, lastname, age, gender, address, address1, city, postelcode, country, newsletter, termsagreed, ip, level, actcode) VALUES
('".mysql_real_escape_string($username)."', '".mysql_real_escape_string(sha1(($password))."', '".mysql_real_escape_string($email)."', '".mysql_real_escape_string($firstname)."', '".mysql_real_escape_string($lastname)."', '".mysql_real_escape_string($age)."', '".mysql_real_escape_string($gender)."', '".mysql_real_escape_string($address)."', '".mysql_real_escape_string($address1)."', '".mysql_real_escape_string($city)."', '".mysql_real_escape_string($postelcode)."', '".mysql_real_escape_string($country)."', '".mysql_real_escape_string($newsletter)."', '".mysql_real_escape_string($termsagreed)."', '".mysql_real_escape_string($ip)."', '".mysql_real_escape_string($level)."', '".mysql_real_escape_string($actcode)."')";

//RQuery result
$rresultaat = mysql_query($rquery);

//If rquery fails
if(!$rresultaat){
header('location: msg.php?msg=registerqfail')
}
else
{
//E-Mail the user his act var
$receiver = $email;
$subject = 'Account Activation';
$headers = 'From: no-reply@'.$leaguesdomain.'' . "\r\n" .
'Reply-To: no-reply@'.$leaguesdomain.'' . "\r\n" .
'MIME-Version: 1.0' . "\r\n" .
'Content-Type: text/html; charset=ISO-8859-1' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
'X-Priority: 1' . "\r\n" .
$msg = '<h3>Profiel Aangemaakt</h3>
Dear '.$firstname.' '.$lastname.' aKa '.$username.',<br />
You just registered an account on '.$leaguesfullname.' with the following information:
<h3>Account Information</h3>
<p>Username: '.$username.'<br />
Password: '.$password.'</p>
<h3>Account Activation</h3>
<p>You need to activate your account to play battles on '.$leaguesfullname.'.<br />
You can click the following url to activate your account.</p>
<p>Activation: <a href="'.$leaguesaddress.'/activate.php?username='.$username.'&amp;actcode='.$actcode.'">'.$leaguesaddress.'/activate.php?username='.$username.'&amp;actcode='.$actcode.'</a></p>';

//Sent E-mail to user
mail($receiver, $subject, $msg, $headers);

//User registered, Re-Locate client
header('location: msg.php?msg=registersucces')
}
}

?>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="POST" name="register" id="register">
<table align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="left">Username:*</td>
<td align="center"><input type="text" name="username" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="left">Password:*</td>
<td align="center"><input type="password" name="password" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="left">Password: (Confirm)*</td>
<td align="center"><input type="password" name="password1" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="left">E-Mail:*</td>
<td align="center"><input type="text" name="email" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="left">E-Mail: (Confirm)*</td>
<td align="center"><input type="text" name="email1" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="left">First Name:*</td>
<td align="center"><input type="text" name="firstname" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="left">Last Name:*</td>
<td align="center"><input type="text" name="lastname" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="left">Age:*</td>
<td align="center"><input type="text" name="age" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="left">Gender:*</td>
<td align="center"><select name="gender">
<option value="male" <?php if (!(strcmp("male", ""))) {echo "SELECTED";} ?>>Male</option>
<option value="female" <?php if (!(strcmp("female", ""))) {echo "SELECTED";} ?>>Female</option>
</select></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="left">Address Line 1:</td>
<td align="center"><input type="text" name="address1" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="left">Address Line 2:</td>
<td align="center"><input type="text" name="address2" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="left">City:</td>
<td align="center"><input type="text" name="city" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="left">Postelcode:</td>
<td align="center"><input type="text" name="postelcode" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="left">Country:</td>
<td align="center"><input type="text" name="country" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="left">Newsletter:</td>
<td align="center"><select name="newsletter">
<option value="yes" <?php if (!(strcmp("yes", ""))) {echo "SELECTED";} ?>>Yes, Please sent me the montly newsletter.</option>
<option value="no" <?php if (!(strcmp("no", ""))) {echo "SELECTED";} ?>>No, I do not want to receive the montly newsletter</option>
</select></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="left">Termsagreed:*</td>
<td align="center"><select name="termsagreed">
<option value="no" <?php if (!(strcmp("no", ""))) {echo "SELECTED";} ?>>No, I do not agree with the Terms of Service</option>
<option value="yes" <?php if (!(strcmp("yes", ""))) {echo "SELECTED";} ?>>Yes, I agree with the Terms of Service</option>
</select></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="left">Ip:</td>
<td align="center"><b><?php echo $_SERVER['REMOTE_ADDR']; ?></b></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="center" colspan="2"><input type="submit" value="Register" name="submit"/></td>
</tr>
</table>
<input type="hidden" name="userid" value="" />
<input type="hidden" name="level" value="user" />
<input type="hidden" name="MM_insert" value="register" />
</form>
<p>&nbsp;</p>
Wat een gruwelijk script om aan te zien. Om je fout te verhelpen kijk je simpelweg op line 6, daar zie je op het eind een } staan die niet klopt.

Niet bedoeld om je te beledigen, maar je hebt nog heel wat te leren over goed scripten. Je zit onnodig variabelen te kopieren, gebruik functies onnodig en verkeerd, gebruikt geen goede foutafhandeling. Haalt vars niet altijd buiten quotes. Als ik zometeen tijd heb zal ik in m'n edit laten zien wat ik bedoel met een globale rewrite van je code. Ik probeer je slechts goed scripten aan te leren, daar help je jezelf, en je bezoekers enorm mee namelijk!

EDIT: dit zou het eerste gedeelte ongeveer in ieder geval moeten worden, al is hier ook nog heel wat aan op te merken:

<?php

require_once('Connections/Leagues.php');

//Check if user is already logged in
if(isset($_SESSION['USERID'])){header('location: msg.php?msg=alreadyloggedin')};

if($_SERVER['REQUEST_METHOD'] == 'POST'){

//username, password, password1, email, email1, firstname, lastname, age,, gender, address1, address1, city
// postelcode, country, newsletter, termsagreed, level

//Check if required vars are filled
if(empty($_POST['username'])){header('location: msg.php?msg=enterusername')};
if(empty($_POST['password'])){header('location: msg.php?msg=enterpassword')};
if(empty($_POST['password1'])){header('location: msg.php?msg=enterpassword1')};
if(empty($_POST['email'])){header('location: msg.php?msg=enteremail')};
if(empty($_POST['email1'])){header('location: msg.php?msg=enteremail1')};
if(empty($_POST['firstname'])){header('location: msg.php?msg=enterfirstname')};
if(empty($_POST['lastname'])){header('location: msg.php?msg=enterlastname')};
if(empty($_POST['age'])){header('location: msg.php?msg=enterage')};
if(empty($_POST['gender'])){header('location: msg.php?msg=entergender')};
if(empty($_POST['termsagreed'])){header('location: msg.php?msg=entertermsagreed')};

//Check if required vars have there lengt
if(strlen($_POST['username']) > 4){header('location: msg.php?msg=usernameshort')};
if(strlen($password) > 4){header('location: msg.php?msg=passwordshort')};
if(strlen($password1) > 4){header('location: msg.php?msg=password1short')};
if(strlen($email) > 6){header('location: msg.php?msg=emailshort')};
if(strlen($email1) > 6){header('location: msg.php?msg=email1short')};
if(strlen($_POST['firstname']) > 2){header('location: msg.php?msg=firstnameshort')};
if(strlen($_POST['lastname']) > 2){header('location: msg.php?msg=lastnameshort')};

//Check if vars are confirmed
if($_POST['password'] != $_POST['password1']){header('location: msg.php?msg=passwordnoconfirm')};
if($_POST['email'] != $_POST['email1']){header('location: msg.php?msg=emailnoconfirm')};


//Check if vars already exists
$query = "SELECT * FROM users WHERE username = '".mysql_real_escape_string($_POST['username'])."'";
if(!$result = mysql_query($query)){
trigger_error(mysql_error());
}
else{
$numrows = mysql_num_rows($result);
if($numrows != 0){
header('location: msg.php?msg=usernameinuse');
}
}
$query2 = "SELECT * FROM users WHERE username = '".mysql_real_escape_string($_POST['email'])."'";
if(!$result2 = mysql_query($query2)){
trigger_error(mysql_error());
}
else{
$numrows2 = mysql_num_rows($result2);
if($numrows2 != 0){
header('location: msg.php?msg=emailinuse');
}
}

//Generate activation var
$actcode = mt_srand((double)microtime()*100000);
while(strlen($actcode) <= 10)
{
$i = chr(mt_rand(0,255));
if(eregi('^[a-z0-9]$', $i))
{
$actcode = $actcode.$i;
}
}

//Var insert query
rquery = "INSERT INTO users (username, password, email, firstname, lastname, age, gender, address, address1, city, postelcode, country, newsletter, termsagreed, ip, level, actcode) VALUES
('".mysql_real_escape_string($_POST['username'])."',
'".sha1(($_POST['password']))."',
'".mysql_real_escape_string($_POST['email'])."',
'".mysql_real_escape_string($_POST['firstname'])."',
'".mysql_real_escape_string($_POST['lastname'])."',
'".mysql_real_escape_string($_POST['age'])."',
'".mysql_real_escape_string($_POST['gender'])."',
'".mysql_real_escape_string($_POST['adress'])."',
'".mysql_real_escape_string($_POST['adress1'])."',
'".mysql_real_escape_string($_POST['city'])."',
'".mysql_real_escape_string($_POST['postelcode'])."',
'".mysql_real_escape_string($_POST['country'])."',
'".mysql_real_escape_string($_POST['newsletter'])."',
'".mysql_real_escape_string($_POST['termsagreed'])."',
'".$_SERVER["REMOTE_ADDR"]."',
'".mysql_real_escape_string($_POST['level'])."',
'".mysql_real_escape_string($actcode)."')";

//RQuery result
$rresultaat = mysql_query($rquery);

//If rquery fails
if(!$rresultaat){
header('location: msg.php?msg=registerqfail')
}
else
{
//E-Mail the user his act var
$receiver = $_POST['email'];
$subject = 'Account Activation';
$headers = 'From: no-reply@'.$leaguesdomain.'' . "\r\n" .
'Reply-To: no-reply@'.$leaguesdomain.'' . "\r\n" .
'MIME-Version: 1.0' . "\r\n" .
'Content-Type: text/html; charset=ISO-8859-1' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
'X-Priority: 1' . "\r\n" .
$msg = '<h3>Profiel Aangemaakt</h3>
Dear '.$_POST['firstname'].' '.$_POST['lastname'].' aKa '.$_POST['username'].',<br />
You just registered an account on '.$leaguesfullname.' with the following information:
<h3>Account Information</h3>
<p>Username: '.$_POST['username'].'<br />
Password: '.$_POST['password'].'</p>
<h3>Account Activation</h3>
<p>You need to activate your account to play battles on '.$leaguesfullname.'.<br />
You can click the following url to activate your account.</p>
<p>Activation: <a href="'.$leaguesaddress.'/activate.php?username='.$_POST['username'].'&amp;actcode='.$actcode.'">'.$leaguesaddress.'/activate.php?username='.$_POST['username'].'&amp;actcode='.$actcode.'</a></p>';

//Sent E-mail to user
mail($receiver, $subject, $msg, $headers);

//User registered, Re-Locate client
header('location: msg.php?msg=registersucces')
}
}

?>
om iets preciezer te zijn.

Regel 6 } en ; omwisselen

Reageren