Jump to content

[SOLVED] help finding error


dolcezza

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.