SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard billy_111's Avatar
    Join Date
    Jul 2009
    Posts
    1,683
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why do i get this error?

    Hey,

    Take a look at this page:-

    http://www.glofamily.com/inner/member-discounts/

    As you can see there are 3 errors on the page:-

    Notice: Undefined index: loggedin in /domains/glofamily.com/http/inner/member-discounts/index.php on line 66
    How this page works is the user enters a password in the "Already a member?" box at the top of the page. Currently this is set to '999999', once this is entered the table below this shows different results, try it you want.

    If i enter a password and it matched the error is not seen, so its only when the user first visits the page.

    My code is show below:-

    PHP Code:
        public function selectPassword(){

            
    $sql "SELECT *
                    FROM tbl_password
                    WHERE password = '"
    .(mysql_real_escape_string($_POST['password']))."'";
            
    $result mysql_query($sql);
            
    $num_rows mysql_num_rows($result);

            if(
    $num_rows 0)
            {
                
    $_SESSION['loggedin'] = true;;
                return 
    true;
            }else{
                return 
    false;
            }
        } 
    PHP Code:
    //Login 
    if(isset($_POST['btn_submit']))
    {
        if(!
    Discount::selectPassword()){
            echo 
    "<script>window.onload = show; function show(){ alert('Invalid password. Please try again.');}</script>";
        }


    PHP Code:
            <table cellspacing="0">
            <th class="th-company">Company</th>
            <th class="th-discount">Discount</th>
            <th class="th-redeem">Discount code / How to redeem</th>
                    
            <?
            $discount 
    Discount::selectAll();
            
    $i 0;
            while(
    $row mysql_fetch_array($discount)){
            
    ?>
            <tr>
            <td class="td-company"><?=$row['company_name']?></td>
            <td class="td-discount"><?=$row['discount']?></td>
            
            <? if ($_SESSION['loggedin'] != false) {?>
            <td class="td-redeem" style="text-align:center"><?=$row['code']?></td>
            <?
            
    } else { ?>
            <td class="td-redeem"><a href="<?=$siteaddress?>join-now"><img src="../images/join.jpg" alt="" border="0"/></a> 
            <? ?>        
            </td>
            </tr>
            
            <?  
            
    }
            
    ?>    
                    </table>
    This code works when the SESSION['loggedin'] exists..

    Any ideas why i get the error?
    Software Engineer ASP, ASP.NET, VB, PHP

    Kind regards
    Billy

  2. #2
    SitePoint Evangelist AlienDev's Avatar
    Join Date
    Feb 2007
    Location
    UK
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Because $_SESSION['loggedin'] isn't set yet.
    Me on StackOverflow | Blog & personal website.

    I mostly use: PHP, Java, JavaScript, Android.

  3. #3
    SitePoint Wizard billy_111's Avatar
    Join Date
    Jul 2009
    Posts
    1,683
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ahh ok, so how could i resolve this issue?

    I thought of doing something like this:-

    PHP Code:
    //Login 
    if(isset($_POST['btn_submit']))
    {
        if(!
    Discount::selectPassword()){
            echo 
    "<script>window.onload = show; function show(){ alert('Invalid password. Please try again.');}</script>";
        }
        else
        {
        
    $_SESSION['loggedin'] = true;
        }
    }
    ?> 
    But this didnt work, any ideas?
    Software Engineer ASP, ASP.NET, VB, PHP

    Kind regards
    Billy

  4. #4
    SitePoint Wizard billy_111's Avatar
    Join Date
    Jul 2009
    Posts
    1,683
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry wrong way of doing it, i fixed the code by doing it like this:-

    PHP Code:
    if(isset($_SESSION['logginin']))
    {

    //


    This worked for me
    Software Engineer ASP, ASP.NET, VB, PHP

    Kind regards
    Billy


Bookmarks

Posting Permissions

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