Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    Regular Coder
    Join Date
    Feb 2006
    Posts
    110
    Thanks
    23
    Thanked 0 Times in 0 Posts

    Unable to read/display Name

    I have this membership code in php/mysql and it works.

    What i want to do here is to display the "name" and have the name field removed from the login form. However, if i remove the "name" field, it displays an error:
    Code:
    Notice: Undefined index: name in /Applications/XAMPP/xamppfiles/htdocs/member1/index.php on line 22
    Here's the working PHP code with the name. What should i do so that i can display the "name" but have the name field removed from the login form?

    PHP Code:
    <?php
    session_start
    ();
    ?>
    <?php 
    include "config.php"?>

    <?php
    if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['uc']) && !empty($_SESSION['name']))
    {
         
    ?>
        
        <h3>Welcome</h3>
    <p>your uc is <strong><?=$_SESSION['uc']?></strong></p>
    <p>your name is <strong><?=$_SESSION['name']?></strong></p>

        <p>&nbsp;</p><p align="right">[ <a href="logout.php">logout</a> ]</p>
        
        <?php
    }
    elseif(!empty(
    $_POST['uc']) && !empty($_POST['mobile']))
    {
         
    $uc mysql_real_escape_string($_POST['uc']);
         
    $name mysql_real_escape_string($_POST['name']);
        
    $mobile md5(mysql_real_escape_string($_POST['mobile']));
        
         
    $checklogin mysql_query("SELECT * FROM users WHERE uc = '".$uc."' AND mobile = '".$mobile."' AND name = '".$name."'");
        
        if(
    mysql_num_rows($checklogin) == 1)
        {
             
    $row mysql_fetch_array($checklogin);

            
    $_SESSION['uc'] = $uc;
            
    $_SESSION['name'] = $name;
            
    $_SESSION['LoggedIn'] = 1;
            
             echo 
    "<h1>Success - redirecting</h1>";
            echo 
    "<meta http-equiv='refresh' content='10;index.php' />";
        }
        else
        {
             echo 
    "<h1>Error</h1>";
        }
    }
    else
    {
        
    ?>

        <h1>Members Login</h1>
        <form method="post" action="index.php" name="loginform" id="loginform">
    <input type="text" name="uc" id="uc" size="40" /></td><td width="10%">&nbsp; 
    <input type="text" name="name" id="uc" size="40" /></td><td width="10%">&nbsp; 
    <input type="text" name="mobile" id="mobile" size="40"/></td><td width="10%">&nbsp; 
    <input class="button_text" type="submit" name="login" id="login" value="Login" />
        </form>
        
       <?php
    }
    ?>
    Thank You.

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,089
    Thanks
    23
    Thanked 593 Times in 592 Posts
    Your biggest problem is using two(2) IDs with the same name:
    <input type="text" name="uc" id="uc" size="40" /></td><td width="10%">&nbsp;
    <input type="text" name="name" id="uc" size="40" /></td><td width="10%">&nbsp;
    and get rid of the <td> tags
    Last edited by sunfighter; 09-16-2013 at 04:33 PM.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #3
    Regular Coder
    Join Date
    Feb 2006
    Posts
    110
    Thanks
    23
    Thanked 0 Times in 0 Posts
    <td> and <id> tag makes no difference. I had strip it down for your easy easy and id was ignored. Thanks for pointing that out.

    I think you mistook my intentions. let me explain again with the error report. Below is the full php code:

    PHP Code:
    <?php
    session_start
    ();

    $dbhost "localhost";
    $dbname "member1";
    $dbuser "root";
    $dbpass "";

    mysql_connect($dbhost$dbuser$dbpass) or die("MySQL Error: " mysql_error());
    mysql_select_db($dbname) or die("MySQL Error: " mysql_error());
    ?>

    <?php
    if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['uc']))
    {
         
    ?>
        
    <h3>Welcome</h3>
    <p>your uc is <strong><?=$_SESSION['uc']?></strong></p>
    <p>your name is <strong><?=$_SESSION['name']?></strong></p>

        <?php
    }
    elseif(!empty(
    $_POST['uc']) && !empty($_POST['mobile']))
    {
         
    $uc mysql_real_escape_string($_POST['uc']);
        
    $mobile md5(mysql_real_escape_string($_POST['mobile']));
        
         
    $checklogin mysql_query("SELECT * FROM users WHERE uc = '".$uc."' AND name = '".$name."' AND mobile = '".$mobile."'");
        
        if(
    mysql_num_rows($checklogin) == 1)
        {
             
    $row mysql_fetch_array($checklogin);
            
    $email $row['email'];
            
            
    $_SESSION['uc'] = $uc;
            
    $_SESSION['email'] = $email;
            
    $_SESSION['name'] = $name;
            
    $_SESSION['LoggedIn'] = 1;
            
             echo 
    "<h1>Success - redirecting</h1>";
            echo 
    "<meta http-equiv='refresh' content='2;index.php' />";
        }
        else
        {
             echo 
    "<h1>Error</h1>";
        }
    }
    else
    {
        
    ?>

        <h1>Members Login</h1>
        <form method="post" action="index.php" name="loginform" id="loginform">
    uc <input type="text" name="uc" id="uc" size="40" />&nbsp;
    mobile <input type="text" name="mobile" id="mobile" size="40"/>&nbsp; 
    <input class="button_text" type="submit" name="login" id="login" value="Login" />
        </form>
        
       <?php
    }
    ?>

    </div>
    </body>
    </html>
    Once i logged in, i see this:

    PHP Code:
    Welcome

    your uc is 999

    your name is 
    Notice
    Undefined indexname in /Applications/XAMPP/xamppfiles/htdocs/member1/rdvmembers-index.php on line 20 
    Hope this clears up what i'm trying to achieve here. thank you.

  • #4
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,089
    Thanks
    23
    Thanked 593 Times in 592 Posts
    Your error is occuring because you removed
    Code:
    name <input type="text" name="uc" id="name" size="40" />&nbsp;
    from the forum. So $_SESSION['name'] = $name; is not set.

    Remember to clear your sessions before checking your code.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #5
    Regular Coder
    Join Date
    Feb 2006
    Posts
    110
    Thanks
    23
    Thanked 0 Times in 0 Posts
    Yes, i know!!!

    I removed it because I want them to type just the uc & mobile and have the name retrieved from the database on successful login.

    I'm unable to figure out how to let show/display the name after successfully logging in.

    Hope that clears it up.

  • #6
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,089
    Thanks
    23
    Thanked 593 Times in 592 Posts
    Then you need to add $name = $row['name']; after $email = $row['email'];
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #7
    Regular Coder
    Join Date
    Feb 2006
    Posts
    110
    Thanks
    23
    Thanked 0 Times in 0 Posts
    thank you for the quick reply but i'm afraid that's giving me another error on line 30:

    PHP Code:
    NoticeUndefined variablename in /Applications/XAMPP/xamppfiles/htdocs/member1/rdvmembers-index.php on line 30
    Error 
    Here's the modified code looks like along with line 30 as commented:
    PHP Code:
    <?php
    session_start
    ();

    $dbhost "localhost";
    $dbname "member1";
    $dbuser "root";
    $dbpass "";

    mysql_connect($dbhost$dbuser$dbpass) or die("MySQL Error: " mysql_error());
    mysql_select_db($dbname) or die("MySQL Error: " mysql_error());
    ?>

    <?php
    if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['uc']))
    {
         
    ?>
        
    <h3>Welcome</h3>
    <p>your uc is <strong><?=$_SESSION['uc']?></strong></p>
    <p>your name is <strong><?=$_SESSION['name']?></strong></p>
    <a href="logout.php">logout</a>

        <?php
    }
    elseif(!empty(
    $_POST['uc']) && !empty($_POST['mobile']))
    {
         
    $uc mysql_real_escape_string($_POST['uc']);
        
    $mobile md5(mysql_real_escape_string($_POST['mobile']));
        
    //The line below is 30 which is showing error. If i remove the name tag, it gives me another error!
         
    $checklogin mysql_query("SELECT * FROM users WHERE uc = '".$uc."' AND name = '".$name."' AND mobile = '".$mobile."'");
        
        if(
    mysql_num_rows($checklogin) == 1)
        {
             
    $row mysql_fetch_array($checklogin);
            
    $email $row['email'];
            
    $name $row['name'];
            
            
    $_SESSION['uc'] = $uc;
            
    $_SESSION['email'] = $email;
            
    $_SESSION['name'] = $name;
            
    $_SESSION['LoggedIn'] = 1;
            
             echo 
    "<h1>Success - redirecting</h1>";
            echo 
    "<meta http-equiv='refresh' content='5;rdvmembers-index.php' />";
        }
        else
        {
             echo 
    "<h1>Error</h1>";
        }
    }
    else
    {
        
    ?>

        <h1>Members Login</h1>
        <form method="post" action="rdvmembers-index.php" name="loginform" id="loginform">
    uc <input type="text" name="uc" id="uc" size="40" />&nbsp;
    mobile <input type="text" name="mobile" id="mobile" size="40"/>&nbsp; 
    <input class="button_text" type="submit" name="login" id="login" value="Login" />
        </form>
        
       <?php
    }
    ?>

    </div>
    </body>
    </html>

  • #8
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,089
    Thanks
    23
    Thanked 593 Times in 592 Posts
    I don't know why you don't see what's wrong
    $checklogin = mysql_query("SELECT * FROM users WHERE uc = '".$uc."' AND name = '".$name."' AND mobile = '".$mobile."'");

    Not defined, your going to get that from the DB. Remove it.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #9
    Regular Coder
    Join Date
    Feb 2006
    Posts
    110
    Thanks
    23
    Thanked 0 Times in 0 Posts
    removing it gives me another error:

    PHP Code:
    NoticeUndefined indexemail in /Applications/XAMPP/xamppfiles/htdocs/member1/rdvmembers-index.php on line 35

    Notice
    Undefined indexname in 
    /Applications/XAMPP/xamppfiles/htdocs/member1/rdvmembers-index.php on line 36 
    and still no name!

  • #10
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,089
    Thanks
    23
    Thanked 593 Times in 592 Posts
    Undefined index: name
    means that you do not have a column titled name in the table called "users"
    Look at it with phpMyAdmin
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #11
    Regular Coder
    Join Date
    Feb 2006
    Posts
    110
    Thanks
    23
    Thanked 0 Times in 0 Posts
    sadly, that is not the case. The name field exists.

    When i include the name field in the login form with a few modifications, it works and displays the name. here's the working code with no error for the same database:

    PHP Code:
    <?php
    session_start
    ();

    $dbhost "localhost";
    $dbname "member1";
    $dbuser "root";
    $dbpass "";

    mysql_connect($dbhost$dbuser$dbpass) or die("MySQL Error: " mysql_error());
    mysql_select_db($dbname) or die("MySQL Error: " mysql_error());
    ?>

    <?php
    if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['uc']))
    {
         
    ?>
        
    <h3>Welcome</h3>
    <p>your uc is <strong><?=$_SESSION['uc']?></strong></p>
    <p>your name is <strong><?=$_SESSION['name']?></strong></p>
    <a href="logout.php">logout</a>

        <?php
    }
    elseif(!empty(
    $_POST['uc']) && !empty($_POST['mobile']))
    {
         
    $uc mysql_real_escape_string($_POST['uc']);
         
    $name mysql_real_escape_string($_POST['name']);
        
    $mobile md5(mysql_real_escape_string($_POST['mobile']));
        
         
    $checklogin mysql_query("SELECT * FROM users WHERE uc = '".$uc."' AND name = '".$name."' AND mobile = '".$mobile."'");
        
        if(
    mysql_num_rows($checklogin) == 1)
        {
             
    $row mysql_fetch_array($checklogin);
            
            
    $_SESSION['uc'] = $uc;
            
    $_SESSION['name'] = $name;
            
    $_SESSION['LoggedIn'] = 1;
            
             echo 
    "<h1>Success - redirecting</h1>";
            echo 
    "<meta http-equiv='refresh' content='2;rdvmembers-index.php' />";
        }
        else
        {
             echo 
    "<h1>Error</h1>";
        }
    }
    else
    {
        
    ?>

        <h1>Members Login</h1>
        <form method="post" action="rdvmembers-index.php" name="loginform" id="loginform">
    uc <input type="text" name="uc" id="uc" size="40" />&nbsp;
    name <input type="text" name="name" id="name" size="40" />&nbsp;
    mobile <input type="text" name="mobile" id="mobile" size="40"/>&nbsp; 
    <input class="button_text" type="submit" name="login" id="login" value="Login" />
        </form>
        
       <?php
    }
    ?>

    </div>
    </body>
    </html>
    I can't figure out how to remove the name field from the form and have it displayed

  • #12
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,089
    Thanks
    23
    Thanked 593 Times in 592 Posts
    Look at the databse with phpMyAdmin!

    Undefined index: name
    means that you do not have a column titled `name` in the table called "users"

    or whats there is not kosher, maybe the column title is Name. Look at the databse with phpMyAdmin!
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • Users who have thanked sunfighter for this post:

    hackerzlab (09-17-2013)

  • #13
    Regular Coder
    Join Date
    Feb 2006
    Posts
    110
    Thanks
    23
    Thanked 0 Times in 0 Posts
    interesting!!! Never knew the database is case sensitive.

    WOW!! Thank you

    Edit: How come it works when i have the name field in the form?!


  •  

    Posting Permissions

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