dolcezza Posted December 6, 2007 Share Posted December 6, 2007 This is my error: Parse error: syntax error, unexpected $end in /home/care/public_html/php/login.php on line 69 There is nothing but the php closing tag on this line. Can anyone help me figure out where I went wrong? Greatly appreciated!! <? ob_start(); session_start(); require_once("db_connect.php"); if (isset($_SESSION['username']) && isset($_SESSION['user_password'])) { header("Location: https://www.caregivingsocal.com/php/loggedin.php"); } if(isset($_POST['submit'])) { if(!$_POST['username']) die("Error: You must enter your username to log in."); if(!$_POST['user_password']) die("Error: You must enter a password to log in."); //set cookie if checked if(!empty($_POST['stay_in'])) { $joined =''.$_POST['username'].'[]'.md5($_POST['user_password']).''; setcookie('login_cookie', $joined, 2147483647, '/','www.caregivingsocal.com'); } // end if //verify user $get_user = mysql_query("SELECT * FROM mem WHERE username = '".$_POST['username']."' AND user_password = '".md5($_POST['user_password'])."'"); $q = mysql_fetch_object($get_user); if(!$q) die("Login Failure: Please verify your username and password are correct." . mysql_error()); $row = mysql_fetch_array($query); // now we check if they are activated if(mysql_num_rows($query) > 0) { if($row['Activated'] > 0) { // set session variables $_SESSION['logged_in'] = 1; $_SESSION['username'] = $_POST['username']; $_SESSION['user_password'] = $_POST['user_password']; Header("Location: https://www.caregivingsocal.com/php/loggedin.php"); } else { ?> <html> <head> <title>Login</title> <link href="style.css" rel="stylesheet" type="text/css"> </head> <body> <div id="error"><p>Sorry, you must activate your account first. Please check your email for the email.</p> <p>Didn'."'".'t get your validation email? <a href="resend.php">Click here</a> to resend the validation email.</p></div> </body> </html> <? } } else { //show login form ?> <form name="login" method="post" action="<?$_SERVER['PHP_SELF']; ?>"> <table> <tr><td>Username:</td><td><input type="text" id="username" name="username"></td></tr> <tr><td>Password:</td><td><input type="password" id="user_password" name="user_password"></td></tr> <tr><td>Submit: <input type="submit" value="submit" name="submit" id="submit"></td></tr> <tr><td><input type="checkbox" name="stay_in[]" checked="yes">Remember Me</td></tr></table></form> <? } // end else ?> Link to comment https://forums.phpfreaks.com/topic/80413-solved-help-finding-error/ Share on other sites More sharing options...
~n[EO]n~ Posted December 6, 2007 Share Posted December 6, 2007 Your coding is too confusing, try to indent properly and keep comments too.... check your code, there is confusion in $q and $query 1 of them is not defined... <?php ob_start(); session_start(); require_once("db_connect.php"); # Check session..... if (isset($_SESSION['username']) && isset($_SESSION['user_password'])) { header("Location: https://www.caregivingsocal.com/php/loggedin.php"); } # Submit button is clicked.... if(isset($_POST['submit'])) { #check if username is empty.... if(!$_POST['username']) { echo ("Error: You must enter your username to log in."); } #check if username is empty.... if(!$_POST['user_password']) { echo ("Error: You must enter a password to log in."); } //set cookie if checked if(!empty($_POST['stay_in'])) { $joined =''.$_POST['username'].'[]'.md5($_POST['user_password']).''; setcookie('login_cookie', $joined, 2147483647, '/','www.caregivingsocal.com'); } //verify user $get_user = mysql_query("SELECT * FROM mem WHERE username = '".$_POST['username']."' AND user_password = '".md5($_POST['user_password'])."'"); $q = mysql_fetch_object($get_user); if(!$q) die("Login Failure: Please verify your username and password are correct." . mysql_error()); $row = mysql_fetch_array($query); // <-- Where is $query // now we check if they are activated if(mysql_num_rows($query) > 0) // <-- here also ..... { if($row['Activated'] > 0) { // set session variables $_SESSION['logged_in'] = 1; $_SESSION['username'] = $_POST['username']; $_SESSION['user_password'] = $_POST['user_password']; header("Location: https://www.caregivingsocal.com/php/loggedin.php"); } } else { ?> <html> <head> <title>Login</title> <link href="style.css" rel="stylesheet" type="text/css"> </head> <body> <div id="error"><p>Sorry, you must activate your account first. Please check your email for the email.</p> <p>Didn'."'".'t get your validation email? <a href="resend.php">Click here</a> to resend the validation email.</p></div> </body> </html> <? } } else { //show login form ?> <form name="login" method="post" action="<?php $_SERVER['PHP_SELF']; ?>"> <table> <tr><td>Username:</td><td><input type="text" id="username" name="username"></td></tr> <tr><td>Password:</td><td><input type="password" id="user_password" name="user_password"></td></tr> <tr><td>Submit: <input type="submit" value="submit" name="submit" id="submit"></td></tr> <tr><td><input type="checkbox" name="stay_in[]" checked="yes">Remember Me</td></tr></table></form> <? } // end else ?> Link to comment https://forums.phpfreaks.com/topic/80413-solved-help-finding-error/#findComment-407720 Share on other sites More sharing options...
dolcezza Posted December 6, 2007 Author Share Posted December 6, 2007 Thanks, I read some tutorials, and I am trying to use different parts of each while changing things myself, since it comes from different sources I keep letting what I read influence me. I need to get used to one organizational style. It's still doing the same thing, only the line is 72 now since I moved everthing. <? ob_start(); session_start(); require_once("db_connect.php"); if (isset($_SESSION['username']) && isset($_SESSION['user_password'])) { header("Location: https://www.caregivingsocal.com/php/loggedin.php"); } if(isset($_POST['submit'])) { if(!$_POST['username']) die("Error: You must enter your username to log in."); if(!$_POST['user_password']) die("Error: You must enter a password to log in."); //set cookie if checked if(!empty($_POST['stay_in'])) { $joined =''.$_POST['username'].'[]'.md5($_POST['user_password']).''; setcookie('login_cookie', $joined, 2147483647, '/','www.caregivingsocal.com'); } // end if //verify user $get_user = mysql_query("SELECT * FROM mem WHERE username = '".$_POST['username']."' AND user_password = '".md5($_POST['user_password'])."'"); $q = mysql_fetch_object($get_user); if(!$q) die("Login Failure: Please verify your username and password are correct." . mysql_error()); $row = mysql_fetch_array($get_user); // now we check if they are activated if(mysql_num_rows($get_user) > 0) { if($row['Activated'] > 0) { // set session variables $_SESSION['logged_in'] = 1; $_SESSION['username'] = $_POST['username']; $_SESSION['user_password'] = $_POST['user_password']; Header("Location: https://www.caregivingsocal.com/php/loggedin.php"); } else { ?> <html> <head> <title>Login</title> <link href="style.css" rel="stylesheet" type="text/css"> </head> <body> <div id="error"><p>Sorry, you must activate your account first. Please check your email for the email.</p> <p>Didn't get your validation email? <a href="resend.php">Click here</a> to resend the validation email.</p></div> </body> </html> <? } } else { //show login form ?> <form name="login" method="post" action="<?$_SERVER['PHP_SELF']; ?>"> <table> <tr><td>Username:</td><td><input type="text" id="username" name="username"></td></tr> <tr><td>Password:</td><td><input type="password" id="user_password" name="user_password"></td></tr> <tr><td>Submit: <input type="submit" value="submit" name="submit" id="submit"></td></tr> <tr><td><input type="checkbox" name="stay_in[]" checked="yes">Remember Me</td></tr></table></form> <? } // end else ?> Howw come on the forum, your code was color coded and mine wasn't? Link to comment https://forums.phpfreaks.com/topic/80413-solved-help-finding-error/#findComment-407727 Share on other sites More sharing options...
rajivgonsalves Posted December 6, 2007 Share Posted December 6, 2007 you forgot a "}" bracket try the following code <?php ob_start(); session_start(); require_once("db_connect.php"); if (isset($_SESSION['username']) && isset($_SESSION['user_password'])) { header("Location: https://www.caregivingsocal.com/php/loggedin.php"); } if(isset($_POST['submit'])) { if(!$_POST['username']) die("Error: You must enter your username to log in."); if(!$_POST['user_password']) die("Error: You must enter a password to log in."); //set cookie if checked if(!empty($_POST['stay_in'])) { $joined =''.$_POST['username'].'[]'.md5($_POST['user_password']).''; setcookie('login_cookie', $joined, 2147483647, '/','www.caregivingsocal.com'); } } // end if //verify user $get_user = mysql_query("SELECT * FROM mem WHERE username = '".$_POST['username']."' AND user_password = '".md5($_POST['user_password'])."'"); $q = mysql_fetch_object($get_user); if(!$q) die("Login Failure: Please verify your username and password are correct." . mysql_error()); $row = mysql_fetch_array($get_user); // now we check if they are activated if(mysql_num_rows($get_user) > 0) { if($row['Activated'] > 0) { // set session variables $_SESSION['logged_in'] = 1; $_SESSION['username'] = $_POST['username']; $_SESSION['user_password'] = $_POST['user_password']; Header("Location: https://www.caregivingsocal.com/php/loggedin.php"); } else { ?> <html> <head> <title>Login</title> <link href="style.css" rel="stylesheet" type="text/css"> </head> <body> <div id="error"><p>Sorry, you must activate your account first. Please check your email for the email.</p> <p>Didn't get your validation email? <a href="resend.php">Click here</a> to resend the validation email.</p></div> </body> </html> <?php } } else { //show login form ?> <form name="login" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <table> <tr><td>Username:</td><td><input type="text" id="username" name="username"></td></tr> <tr><td>Password:</td><td><input type="password" id="user_password" name="user_password"></td></tr> <tr><td>Submit: <input type="submit" value="submit" name="submit" id="submit"></td></tr> <tr><td><input type="checkbox" name="stay_in[]" checked="yes">Remember Me</td></tr></table></form> <?php } // end else ?> Link to comment https://forums.phpfreaks.com/topic/80413-solved-help-finding-error/#findComment-407731 Share on other sites More sharing options...
~n[EO]n~ Posted December 6, 2007 Share Posted December 6, 2007 little bit late Same thing, you again missed one curly brace (in line 41 while I edited in DW) You spelled header as Header and for color in code, use full <?php tag not only <? (here also and in your code also) Link to comment https://forums.phpfreaks.com/topic/80413-solved-help-finding-error/#findComment-407733 Share on other sites More sharing options...
dolcezza Posted December 6, 2007 Author Share Posted December 6, 2007 Thank you guys so much... I apologize, but I sent the wrong script. I think this means it's bed time. The correct script is working fine. Thanks though, I needed the reminder to neaten up and create good habits from the beginning! I get so absorbed sometimes! Again, thank you. Link to comment https://forums.phpfreaks.com/topic/80413-solved-help-finding-error/#findComment-407736 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.