SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Undefined index

  1. #1
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    323
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Undefined index

    hello , please i am having an undefined index for a script that works well on my host server, it is giving error

    Notice: Undefined index: username in /Users/mgltd/Sites/reacheasy/include/header.php on line 23
    Notice: Undefined index: username in /Users/mgltd/Sites/reacheasy/include/header.php on line 42


    from my header script the mark up is below

    PHP Code:
    <?php require_once("include/session.php");?>
    <?php 
    require_once("include/functions.php");?>
    <?php 
    include("include/header.php");?>
    this is the header script

    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
         <title>Reacheasy - Foremost website for shopping from Uk, and globally to Nigeria</title>
       <meta name="description" content="We offer online shopping and shipping from UK stores to Nigeria" />
        <meta name="keywords" content="shipping to nigeria, freight to nigeria,online shopping from uk" />
        
        
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
    <link href="reasy.css" rel="stylesheet" type="text/css"/>  
    </head>
      <body>
    <div id="outer">
    <div id="page">
    <div id="header">
    <!--<div id="adban" style="position: absolute; left: 50%; margin-left: -150px;">
    <span style="left;"><a href="reregister.php">Click here to Register now and place your orders</a></span>
    </div>-->
    <div id="hlogo">
    <!--<span style="float:right;"><img src="img/relogo2.jpg"  class="logoImage" width="96" height="96"/></span>-->
    <span style="float:right;margin:2px 2px 0 0;"><img src="img/relogo1.jpg"  class="logoImage" width="96" height="96"/></span>
    </div>
    <span style="font-size:small;text-shadow: 10px 10px 1px grey;"><h1>Reacheasy<span style="font-size:small;">
    PHP Code:
    <?php echo $_SESSION['username'];?>
    HTML Code:
    </span></h1></span>
    <!--<span style="float:left;"><img src="img/rewordlogo.jpg"/></span>-->
    <ul id="nav">
        <li class="current"><a href="index.php">Home</a></li>
         <li><a href="women.php">Women</a></li>
         <li><a href="men.php">Men</a></li>
         <li><a href="children.php">Children</a></li>
         <li><a href="homeandappliances.php">Home&amp;Appliances</a></li>
         <li><a href="visionandsound.php">Vision&amp;Sounds</a></li>
          <!--<li><a href="motoring.php">Motoring</a></li>-->
          <li><a href="homemore.php">More</a></li>
          <li><a href="freight.php">Freight</a></li>
          <li><a href="howto.php">Help(How to?)</a></li>
      </ul>
    </div> <!--end of navigation div -->
    </div>
    <div id="navigation">
    PHP Code:
    <?php
    if($_SESSION['username'])
    ?>
    HTML Code:
    <ul id="navigationlb">
    <li><a href='howto.php'>Help(How to?)</a></li>
    <li><a href='notification.php'>Consignment notification</a></li>
    <li><a href='youraccount.php'>Order Placement</a></li>
    <li><a href='relogout.php'>Log out</a></li>
     </ul>
    PHP Code:
    <?php }else{
    ?>
    HTML Code:
     <div>
    <form action='relogin.php' method='post' class='rl'>
    <fieldset>
    <legend>Login</legend>
    	<div>
    	<label for='username' class='fixedwidth'>Username</label>
    	<input type='text' name='username' id='username'/>
    	</div>
    	
    	<div>
    	<label for='password' class='fixedwidth'>Password</label>
    	<input type='password' name='password' id='password'/>
    	</div>
    <div class='buttonarea'>
    	<input type='submit' value='Log in'/>
    	</div>
    <p>
    <a href='reregister.php'>Register </a>
    <span style="font-family:Arial,Helvetica,sans-serif;color:#5CB3FF;"><BR>PLACE YOUR ORDERS FROM ANYWHERE</BR> 
    IN THE WORLD </BR> TO NIGERIA</span>
    </p>
    <!--<p>
    <BR>PLACE YOUR ORDER FROM ANYWHERE</BR> 
    IN THE WORLD </BR> TO NIGERIA
    </p>-->
    </fieldset>
    </form>
    </div>
    PHP Code:
    <?php
    }
    ?>

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Use isset() to check for the existence of a value
    PHP Code:
    if(isset($_SESSION['username']))

    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    323
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    it worked thanks, @mike, whats the difference between the two, because the previous mark up was working fine on line

  4. #4
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Using if() blindly looks for a value and if it's not there it just spits out an error message. isset() will determine if the variable is there or not and return either true or false.
    It might be that your previous server had error reporting turned down or even off.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....


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
  •