Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 6th, 2012, 11:42 PM
Authorized User
 
Join Date: May 2012
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default error in line 27 please help

<?php
include("includes/function.php");
session_start();

if(isset($_POST['login']))
{
if(isset($_POST['username']))
{
if(isset($_POST['password']))
{
$username = $_POST['username'];
$query = mysql_query("select * from users where Username = '$username'") or die(mysql_error());

$user = mysql_fetch_array($query);

if(md5($_POST['password']) == $user['Password'])
{
echo "Login successful";
$_SESSION['user'] = $user['Username'];
header("Location: index.php");
}
else {
echo "Please check you Login details";
include("login.php");
}

else {
echo "Please check you password";
include("login.php");
}
else {
echo "Please check your username";
include("login.php");

}
else {
echo "Please check that you filled out the login form";
include("login.php");
}
}
}
}


?>
 
Old June 6th, 2012, 11:45 PM
Authorized User
 
Join Date: May 2012
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

note::
is there a problem after first else??

i used else if but also no any correction found
 
Old June 7th, 2012, 03:44 AM
Friend of Wrox
 
Join Date: May 2011
Posts: 125
Thanks: 0
Thanked 24 Times in 24 Posts
Default

Greetings,

You are missing some } and the 3 } at the end are not needed.
PHP Code:
<?php
include("includes/function.php");
session_start();

if(isset(
$_POST['login']))
{
    if(isset(
$_POST['username']))
    {
        if(isset(
$_POST['password']))
        {
            
$username $_POST['username'];
            
$query mysql_query("select * from users where Username = '$username'") or die(mysql_error());

            
$user mysql_fetch_array($query);

            if(
md5($_POST['password']) == $user['Password'])
            {
                echo 
"Login successful";
                
$_SESSION['user'] = $user['Username'];
                
header("Location: index.php");
            }
            else
            {
                echo 
"Please check you Login details";
                include(
"login.php");
            }
        }
        else
        {
            echo 
"Please check you password";
            include(
"login.php");
        }
    }
    else
    {
        echo 
"Please check your username";
        include(
"login.php");
    }
}
else
{
    echo 
"Please check that you filled out the login form";
    include(
"login.php");
}

?>
If when starting an if statement you start it like this;
Code:
if( test )
{
then the { needs to be closed BEFORE any else, if an else is required.

Last edited by UseLess; June 7th, 2012 at 03:47 AM..
 
Old June 7th, 2012, 12:22 PM
Authorized User
 
Join Date: May 2012
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ye thanks it worked.. Hats off!! :)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 27: Modules And Handlers - Listing 27.2 Nikhil BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9 0 February 4th, 2010 07:25 AM
Chapter 27 Run-time Error DaveHowland BOOK: Professional VB 2005 ISBN: 0-7645-7536-8 7 February 16th, 2008 09:32 PM
returning error line robertdavies Classic ASP Professional 2 September 30th, 2004 09:06 AM
Parse error on line that does not exist shabboleth Beginning PHP 1 December 19th, 2003 01:41 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.