Results 1 to 9 of 9

Thread: Problem with session and login

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    39

    Problem with session and login

    Hi mate
    Thank you for the reply , sorry another hassle so please tell me what is wrong with this code, it suppose user login or register if they are not a member, when run it gave query not executed, I did check the table field are the same with the query and the database connected. Thank you very much

    to be noted the database connection inside the extenral file "conn.inc.php"
    PHP Code:
    <?php // script to process the registration 

    // initialize variable and register broweser 
    session_start();

    ob_start();

    include 
    "conn.inc.php";

    ?>

    <html>

    <head><title>Management System</title></head>

    <body>

    <?php


    // check for if the user already exist and make sure the field not empty.
    if(isset($_POST['submit']) && $_POST['submit'] == "Register")
    {
            
        if (
    $_POST['username'] != "" && $_POST['password'] != "")
        {
        
            
    //create SQL query
            
    $query "select username from user " "where username = '" $_POST['username'] . "'; ";

            
    #excute the query
            
    $rs mysql_query($query)
            
            or die(
    mysql_error());
            
            
            if (
    mysql_num_rows($rs) != 0)
            {
                
    ?> 
                
                <p>
                
                <font color="Red"> <b>The Username,
                
                <?php 
                
                
    echo $_POST['username']; ?>, is already in use Please choose another 

                </b></font>
                
                <form action="register.php" method="POST">
                
                Username : <input type="text" name="username"> <br>
                
                Password : <input type= "password" name="password" value="<?php echo $_POST['password']; ?>"><br>
                
                <input type="submit" name="submit" value="Register"> &nbsp;
                <input type="reset" value="Clear">

                </form>
                </p>
                
                <?php 
            
    }
            
            else 
            {
                
    //create SQL query
                
    $query"insert into user (username, password) " "values ( '" $_POST['username'] . "', " 
                
    "password('" $_post['password'] . "');";
                
                
    // Excute query
                
    $rs mysql_query($query)
                or die(
    "Query could not excuted");
                
                
    $_SESSION['user_logged'] = $_POST['username'];
                
                
    $_SESSION['user_password'] = $_POST['password'];
                
                
    ?>
                
                <P>
                
                Thank you, <?php echo $_POST['username']; ?> for Registering <br>
                
                <?php 
                
                header
    ("Refresh: 5; URL=index1.php");
                
                echo 
    "Your regiseration is complete" .
                
    "You are being sent to the request page<br>"
                
                echo  
    "(if  your browser doesn't support this, " 
                
    "<a  href=\"index1.php\"> Click here</a>)";  
                die();
                
            }
        }else 
        {
            
    ?> 
            
            <P>
            
            <font color = "red"> The Username and password required</b></font>    
            
            <form action="register.php" method="POST">
            
            Username : <input type="text" name="username" value="<?php echo $_POST['username']; ?>"><br>
            
            Password : <input type="password" name="password" value=""<?php echo $_POST['password']; ?>"><br>
            
            <input type="submit" name="submit" value="Register"> &nbsp;
            
            <input type="reset" value="Clear">
            
            </form>
            </P>
            
            <?php 
        
    }
    }else 
    {
        
    ?>
        <p>
        Welcome to Registeration<br>

        Username and password required
        
        <font color = "red"> username and password required</b></font>    
            
        <form action="register.php" method="POST">
            
        Username : <input type="text" name="username"><br>
            
        Password : <input type="password" name="password"><br>
            
        <input type="submit" name="submit" value="Register"> &nbsp;
            
        <input type="reset" value="Clear">
            
        </form>
        
        </p>
        
        <?php
    }

    ?>
    </body>

    </html>

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: proble with session

    you're missing a bracket. this fixes it:
    PHP Code:
                $query"insert into user (username, password) " "values ( '" $_POST['username'] . "', " 
                
    "password('" $_post['password'] . "'));"
    if you would simply call mysql_error() within your die()'s, you could quickly try to defuse problems like these yourself.

  3. #3
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: proble with session

    Quote Originally Posted by omarali
    Hi mate
    Thank you for the reply , sorry another hassle so please tell me what is wrong with this code, it suppose user login or register if they are not a member, when run it gave query not executed, I did check the table field are the same with the query and the database connected. Thank you very much

    to be noted the database connection inside the extenral file "conn.inc.php"
    PHP Code:
    <?php // script to process the registration 

    // initialize variable and register broweser 
    session_start();

    ob_start();

    include 
    "conn.inc.php";

    ?>

    <html>

    <head><title>Management System</title></head>

    <body>

    <?php


    // check for if the user already exist and make sure the field not empty.
    if(isset($_POST['submit']) && $_POST['submit'] == "Register")
    {
            
        if (
    $_POST['username'] != "" && $_POST['password'] != "")
        {
        
            
    //create SQL query
            
    $query "select username from user " "where username = '" $_POST['username'] . "'; ";

            
    #excute the query
            
    $rs mysql_query($query)
            
            or die(
    mysql_error());
            
            
            if (
    mysql_num_rows($rs) != 0)
            {
                
    ?> 
                
                <p>
                
                <font color="Red"> <b>The Username,
                
                <?php 
                
                
    echo $_POST['username']; ?>, is already in use Please choose another 

                </b></font>
                
                <form action="register.php" method="POST">
                
                Username : <input type="text" name="username"> <br>
                
                Password : <input type= "password" name="password" value="<?php echo $_POST['password']; ?>"><br>
                
                <input type="submit" name="submit" value="Register"> &nbsp;
                <input type="reset" value="Clear">

                </form>
                </p>
                
                <?php 
            
    }
            
            else 
            {
                
    //create SQL query
                
    $query"insert into user (username, password) " "values ( '" $_POST['username'] . "', " 
                
    "password('" $_post['password'] . "');";
                
                
    // Excute query
                
    $rs mysql_query($query)
                or die(
    "Query could not excuted");
                
                
    $_SESSION['user_logged'] = $_POST['username'];
                
                
    $_SESSION['user_password'] = $_POST['password'];
                
                
    ?>
                
                <P>
                
                Thank you, <?php echo $_POST['username']; ?> for Registering <br>
                
                <?php 
                
                header
    ("Refresh: 5; URL=index1.php");
                
                echo 
    "Your regiseration is complete" .
                
    "You are being sent to the request page<br>"
                
                echo  
    "(if  your browser doesn't support this, " 
                
    "<a  href=\"index1.php\"> Click here</a>)";  
                die();
                
            }
        }else 
        {
            
    ?> 
            
            <P>
            
            <font color = "red"> The Username and password required</b></font>    
            
            <form action="register.php" method="POST">
            
            Username : <input type="text" name="username" value="<?php echo $_POST['username']; ?>"><br>
            
            Password : <input type="password" name="password" value=""<?php echo $_POST['password']; ?>"><br>
            
            <input type="submit" name="submit" value="Register"> &nbsp;
            
            <input type="reset" value="Clear">
            
            </form>
            </P>
            
            <?php 
        
    }
    }else 
    {
        
    ?>
        <p>
        Welcome to Registeration<br>

        Username and password required
        
        <font color = "red"> username and password required</b></font>    
            
        <form action="register.php" method="POST">
            
        Username : <input type="text" name="username"><br>
            
        Password : <input type="password" name="password"><br>
            
        <input type="submit" name="submit" value="Register"> &nbsp;
            
        <input type="reset" value="Clear">
            
        </form>
        
        </p>
        
        <?php
    }

    ?>
    </body>

    </html>
    mysql_escape_string() is your friend
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  4. #4

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    39

    proble with login

    Hi
    please help this code doesn't work and keep saying query not exquted and i can't see problem with the query command.

    PHP Code:
    <?php // script to check if the user stored in the MySQL database previously 

    session_start();

    include 
    "conn.inc.php";

    if(isset(
    $_POST['submit']))
    {
        
    $query "select username, password from user  " "where username = '" $_POST['username']  ."'" "ADN  password = (PASSWORD('" $_POST['password'] . " '))";
        
    // excute the query
        
    $result mysql_query($query)
        
        or die(
    "query not excuted");
        
        if(
    mysql_num_rows($result) == 1)
        {
            
    $_SESSION['user_logged'] = $_SESSION['username'];
            
    $_SESSION['user_password'] = $_SESSION['password'];
            
            
    header("Refresh: 5; URL=" $_POST['redirect'] . "");
            echo 
    " you being redirected to your original page reques<br>";
            
            echo 
    "(if your browser not support this, " .
            
    "<a href =\"" $_POST['redirect'] . "\"> Click here</a>)";
            
        }
        else
        {
            
    ?>
            <html>
            <head><title> user_login</title></head>
            <body>
            
            <p>
            
            invalid and /or password<br>
            
            Not registered?
            
            <a href="register.php">Click here</a> to register.<br>
            
            <form action="user_login.php" method="POST">
            
            <input type="hidden" name="redirect" value="<?php echo  $_POST ['redirect']; ?>">
            
            Username : <input type="text" name="username"><br>

            Password : <input type="password" name="password"><br><br>
            
            <input type="submit" name="submit" value="Login">
            
            </form>
            
            </p>
            
            </body>
            </html>
            
            <?php
            
        
    }
        
    }
    else 
    {

        if(isset(
    $_GET['redirect']))
        {
            
    $redirect $_GET['redirect'];
            
        }else 
        {
            
    $redirect ="index1.php";
        }
        
    ?>
        <html>
        
        <head><title>Management system </title></head>
        
        <body>
        
        <p>
        
        login below by supplying your username/password..<br>
        
        or<a href="register.php"> Click here</a> to register.<br><br>
        
        <form action="user_login.php" method="POST">
            
        <input type="hidden" name="redirect" value="<?php echo $redirect?>">
            
        Username : <input type="text" name="username"><br>

        Password : <input type="password" name="password"><br><br>
            
        <input type="submit" name="submit" value="Login">
            
        </form>
        
        </p>
        </body>
        
        </html>
        <?php
    }
    ?>

  5. #5
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: proble with login

    are you getting a mysql error?
    My usual boring signature: Something

  6. #6

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    39

    proble with login

    Hi
    I get query not excute but when I execute the code bellow, I get this error "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''uuu)' at line 1"

    PHP Code:
    <?php // script to process the registration 

    // initialize variable and register broweser 
    session_start();

    ob_start();

    // file contain connection to the database
    include "conn.inc.php";

    ?>

    <html>

    <head><title>Management System</title></head>

    <body>

    <?php


    // check for if the user already exist and make sure the field not empty.
    if(isset($_POST['submit']) && $_POST['submit'] == "Register")
    {
            
        if (
    $_POST['username'] != "" && $_POST['password'] != "")
        {
        
            
    //create SQL query
            
    $query "select  username from users " "where username = '" $_POST['username'] . "';";
             
    //mysql_query($sql) or die(mysql_error()); 
            
            #excute the query
            
    $result mysql_query($query)
            
            or die(
    mysql_error());
            
            
            if (
    mysql_num_rows($result) != 0)
            {
                
    ?> 
                
                <p>
                
                <font color="Red"> <b>The Username,
                
                <?php echo $_POST['username']; ?>, is already in use Please choose another 

                </b></font>
                
                <form action="register.php" method="POST">
                
                Username : <input type="text" name="username"> <br>
                
                Password : <input type= "password" name="password" value="<?php echo $_POST['password']; ?>"><br>
                
                <input type="submit" name="submit" value="Register"> &nbsp;
                <input type="reset" value="Clear">

                </form>
                </p>
                
                <?php 
            
    }
            
            else 
            {
                
    //create SQL query
                
    $query "insert into user(username,password) " "values ('" $_POST['username'] . "', " "(PASSWORD('" $_POST['password'] . ");";

                
    // Excute query
                
    $result mysql_query($query)
                
                or die(
    mysql_error());
                
                
    $_SESSION['user_logged'] = $_POST['username'];
                
                
    $_SESSION['user_password'] = $_POST['password'];
                
                
    ?>
                
                <P>
                
                Thank you, <?php echo $_POST['username']; ?> for Registering <br>
                
                <?php 
                
                header
    ("Refresh: 5; URL=index1.php");
                
                echo 
    "Your regiseration is complete" .
                
    "You are being sent to the request page<br>"
                
                echo  
    "(if  your browser doesn't support this, " 
                
    "<a  href=\"index1.php\"> Click here</a>)";  
                die();
                
            }
        }else 
        {
            
    ?> 
            
            <P>
            
            <font color = "red"> <b>The Username and password required</b></font>    
            
            <form action="register.php" method="POST">
            
            Username : <input type="text" name="username" value="<?php echo $_POST['username']; ?>"><br>
            
            Password : <input type="password" name="password" value="<?php echo $_POST['password']; ?>"><br>
            
            <input type="submit" name="submit" value="Register"> &nbsp;
            
            <input type="reset" value="Clear">
            
            </form>
            </P>
            
            <?php 
        
    }
    }else 
    {
        
    ?>
        <p>
        Welcome to Registeration<br>

        Username and password required
        
        <form action="register.php" method="POST">
            
        Username : <input type="text" name="username"><br>
            
        Password : <input type="password" name="password"><br>
            
        <input type="submit" name="submit" value="Register"> &nbsp;
            
        <input type="reset" value="Clear">
            
        </form>
        
        </p>
        
        <?php
    }

    ?>
    </body>

    </html>

  7. #7
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Problem with session and login

    Threads merged!

  8. #8
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Problem with session and login

    you're STILL missing the bracket I told you about in the first post that I made.. that's the only problem in your script.

  9. #9
    New Member
    Join Date
    Apr 2007
    Posts
    2

    Re: Problem with session and login

    Hi I did fixed the bracket but now when typing to the form withcorrect user and password keep said invalid username and password

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width