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:-


    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;
        }
    }


//Login 
if(isset($_POST['btn_submit']))
{
    if(!Discount::selectPassword()){
        echo "<script>window.onload = show; function show(){ alert('Invalid password. Please try again.');}</script>";
    }
}


		<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?

Because $_SESSION[‘loggedin’] isn’t set yet.

Ahh ok, so how could i resolve this issue?

I thought of doing something like this:-


//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?

Sorry wrong way of doing it, i fixed the code by doing it like this:-

if(isset($_SESSION['logginin']))
{

//

}

This worked for me