Ethan05 Posted November 27, 2007 Share Posted November 27, 2007 I'm pretty new to PHP and I was messing around with a prefab login script to use for my website. I came across a syntax error that I can't make sense of: Parse error: syntax error, unexpected T_ELSE in [siteurl]/login.php on line 71 Offending code: 64 setcookie(cvc123, $_POST['pass'], $hour); 65 // 66 //redirect 67 header("Location: members.php"); 68 } 69 } 70 } 71 else; 72 { I've tried looking around at my semicolons and brackets, but everything checks out. What am I missing? Thanks, Ethan Quote Link to comment Share on other sites More sharing options...
rlindauer Posted November 27, 2007 Share Posted November 27, 2007 remove the semicolon after else Quote Link to comment Share on other sites More sharing options...
Ethan05 Posted November 27, 2007 Author Share Posted November 27, 2007 I did try that, but it didn't seem to make a difference Quote Link to comment Share on other sites More sharing options...
trq Posted November 27, 2007 Share Posted November 27, 2007 Were going to need more code then, nicely indented so it is readable. Quote Link to comment Share on other sites More sharing options...
Ethan05 Posted November 27, 2007 Author Share Posted November 27, 2007 Okay: 60 // if login is good add a cookie 61 $_POST['username'] = stripslashes($_POST['username']); 62 $hour = time() + 3600; 63 setcookie(usernamecv, $_POST['username'], $hour); 64 setcookie(cvc123, $_POST['pass'], $hour); 65 // 66 //redirect 67 header("Location: members.php"); 68 } 69 } 70 } 71 else 72 { 73 // if they are not logged in 74 ?> 75 76 <form method="post" action="<?php echo $_SERVER['PHP_SELF']?>"> 77 <table border="0"> 78 <tbody> 79 <tr> 80 <td colspan="2"> 81 <h1>Login</h1> 82 </td> 83 </tr> 84 <tr> 85 <td>Username:</td> 86 <td><input type="text" maxlength="40" name="username" /></td> 87 </tr> 88 <tr> 89 <td>Password:</td> 90 <td><input type="password" maxlength="50" name="pass" /></td> 91 </tr> 92 <tr> 93 <td align="right" colspan="2"><input type="submit" value="Login" name="submit" /></td> 94 </tr> 95 </tbody> 96 </table> 97 </form> 98 <?php 99 } 100 101 ?> 102 </body> 103 </html> Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted November 27, 2007 Share Posted November 27, 2007 try <?php } else { echo "<html><body><form>"; } ?> Quote Link to comment Share on other sites More sharing options...
Ethan05 Posted November 27, 2007 Author Share Posted November 27, 2007 Still not working :-\ Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted November 27, 2007 Share Posted November 27, 2007 60<?php // if login is good add a cookie 61 $_POST['username'] = stripslashes($_POST['username']); 62 $hour = time() + 3600; 63 setcookie(usernamecv, $_POST['username'], $hour); 64 setcookie(cvc123, $_POST['pass'], $hour); 65 // 66 //redirect 67 header("Location: members.php"); 68 } 69 } 70 } 71 else 72 { 73 // if they are not logged in 74 echo 75 76 "<form method="post" action=" $_SERVER['PHP_SELF']"> 77 <table border="0"> 78 <tbody> 79 <tr> 80 <td colspan="2"> 81 <h1>Login</h1> 82 </td> 83 </tr> 84 <tr> 85 <td>Username:</td> 86 <td><input type="text" maxlength="40" name="username" /></td> 87 </tr> 88 <tr> 89 <td>Password:</td> 90 <td><input type="password" maxlength="50" name="pass" /></td> 91 </tr> 92 <tr> 93 <td align="right" colspan="2"><input type="submit" value="Login" name="submit" /></td> 94 </tr> 95 </tbody> 96 </table> 97 </form>";?> 98 99 100 101 102 </body> 103 </html> Quote Link to comment Share on other sites More sharing options...
trq Posted November 27, 2007 Share Posted November 27, 2007 Darkfreaks, you are changing code after the problem. And making a mess of it I might add. Sorry, we need more code prior to line 71 not after. We need to see what all those braces match up with. Quote Link to comment Share on other sites More sharing options...
Ethan05 Posted November 27, 2007 Author Share Posted November 27, 2007 <?php 23 { //if the login form is submitted if (isset($_POST['submit'])); { // if form has been submitted // makes sure they filled it in if(!$_POST['username'] | !$_POST['pass']) { die('You did not fill in a required field.'); } // checks it against the database if (!get_magic_quotes_gpc()) { $_POST['email'] = addslashes($_POST['email']); } $check = mysql_query("SELECT * FROM phpbb_users WHERE username = '".$_POST['username']."'") or die(mysql_error()); //Gives error if user doesn't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { die('That user does not exist in our database. <a href=add.php>Click Here to Register</a>'); } while($info = mysql_fetch_array( $check )) { $_POST['pass'] = stripslashes($_POST['pass']); $info['password'] = stripslashes($info['password']); $_POST['pass'] = phpbb_hash($_POST['pass']); //gives error if the password is wrong if ($_POST['pass'] != $info['password']) { die('Incorrect password, please try again.'); } else { // if login is good add a cookie $_POST['username'] = stripslashes($_POST['username']); $hour = time() + 3600; setcookie(*******, $_POST['username'], $hour); setcookie(*****, $_POST['pass'], $hour); // //redirect header("Location: members.php"); } } } 70 else ?> Sorry, lines not labeled except for the first and last... I'm using a text editor because I don't have access to anything else on this machine currently. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted November 27, 2007 Share Posted November 27, 2007 your missing a closing } Quote Link to comment Share on other sites More sharing options...
Ethan05 Posted November 27, 2007 Author Share Posted November 27, 2007 At line 71? It's just not in the snippet Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted November 27, 2007 Share Posted November 27, 2007 your missing a closing bracket it needs to befixed Quote Link to comment Share on other sites More sharing options...
Ethan05 Posted November 27, 2007 Author Share Posted November 27, 2007 I realise it needs to be fixed; where? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted November 27, 2007 Share Posted November 27, 2007 there should be an extra closing bracket before line 70 Quote Link to comment Share on other sites More sharing options...
Ethan05 Posted November 27, 2007 Author Share Posted November 27, 2007 Thank you. That's what I needed to know Trying it out now... ... still no good. Hm. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted November 27, 2007 Share Posted November 27, 2007 whats the error you get now? Quote Link to comment Share on other sites More sharing options...
Ethan05 Posted November 27, 2007 Author Share Posted November 27, 2007 Parse error: syntax error, unexpected T_ELSE in /login.php on line 71 Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted November 27, 2007 Share Posted November 27, 2007 i know why it fails you canonly have one else you my friend have 2 make it like if () elseif() elseif() else() Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.