SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2011
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP/MySQL undefined index errors

    I have a simple PHP output drawing from a mysql db. The output is supposed to be nothing more than the selected record(name and address fields) from the db- for simplicity, i have assigned the id as '3' in this example. I am getting the desired result in the browser output, but I am getting errors first stating 'Undefined index'. Why does it tell me this, but then go ahead and output the correct data anyway?

    [browser output]
    Notice: Undefined index: name in C:\wamp\www\coffeejoint\test.php on line 37 [See blue text below]

    Notice: Undefined index: address in C:\wamp\www\coffeejoint\test.php on line 37
    Spunky Monkey35 NE 20th St


    [php code]
    Code PHP:
     

    <?php
    require_once('includes/initialize.php');
    require 'includes/head.html.php'; ?>

    <html>
    <h1> test page </h1>
    <form action = "?" method="post">
    <input type="submit" name="id" value="3" />
    </form>
    <html>

    <?php
    $id = mysql_real_escape_string($_POST['id'] , $connection);
    $view = " SELECT * FROM `shops` WHERE ID = $id";
    $resulta = mysql_query($view, $connection);
    $shopinfo[] = array();
    if(!$resulta)
    {
    $error = 'no resultx' . mysql_error();
    include 'includes/error.html.php';
    exit();
    }
    while($row = mysql_fetch_assoc($resulta))
    {
    $shopinfo[] = array('name' => $row['Name'], 'address' => $row ['Address'],'id' => $row['ID']);
    }
    ?>


    <?php foreach($shopinfo as $resultz): ?>

    <?php echo htmlspecialchars($resultz['name'], ENT_QUOTES, 'UTF-8') . htmlspecialchars($resultz['address'], ENT_QUOTES, 'UTF-8');?>

    <?php endforeach;
    exit();
    ?>

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    The error says 'name' not 'Name'
    The line in error is
    Code:
    <?php echo htmlspecialchars($resultz['name'], ENT_QUOTES, 'UTF-8') . htmlspecialchars($resultz['address'], ENT_QUOTES, 'UTF-8');?>
    Why? Because you initialize your $shopinfo array like this:
    Code:
    $shopinfo[] = array();
    so the first occurrance of $shopinfo is an empty array.
    What you want is
    Code:
    $shopinfo = array();

  3. #3
    SitePoint Member
    Join Date
    Aug 2011
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got this on browser when I tried to open the file :

    "Notice: Undefined index: _m in E:\elibrary\index.php on line 8
    Notice: Undefined index: _m in E:\elibrary\index.php on line 10
    Notice: Undefined index: _m in E:\elibrary\index.php on line 17
    Notice: Undefined index: _m in E:\elibrary\index.php on line 23
    Notice: Undefined index: _m in E:\elibrary\index.php on line 29
    Notice: Undefined index: _m in E:\elibrary\index.php on line 35
    Notice: Undefined index: frontend_userid in E:\elibrary\index.php on line 41
    Notice: Undefined index: _m in E:\elibrary\index.php on line 99"

    Below I includes the codes from my index.php file. What is undefined index? Can someone please help me in this problem? I really newbie in php. Really really a newbie. Please help. Its urgent. Thank you.

    PHP Code:
    <?php
     
    session_start
    ();

    include 
    "global.inc.php";
      

    if (
    $_GET["_m"] == "blank") { exit; }

    if (
    $_GET["_m"] == "logout")
    {
        
    auditlogFront("Logout"$_SESSION["frontend_userid"]);
        
    $_SESSION["frontend_userid"] = 0;
        
    header("location:/");
        exit;
    }
    if (
    $_GET["_m"] == "publicuser")
    {
        include 
    "modules/login/module_publicuser.php";
        
    auditlogFront("view publicuser"$_SESSION["frontend_userid"]);
        exit;
    }
    if (
    $_GET["_m"] == "publicuser_search")
    {
        include 
    "modules/login/module_publicuser_search.php";
        
    auditlogFront("search publicuser"$_SESSION["frontend_userid"]);
        exit;
    }
    if (
    $_GET["_m"] == "monograph_info")
    {
        include 
    "modules/login/module_monograph_info.php";
        
    auditlogFront("view monograph info"$_SESSION["frontend_userid"]);
        exit;
    }
    if (
    $_GET["_m"] == "announcement_content")
    {
        include 
    "modules/login/module_announcement_content.php";
        
    auditlogFront("view announcement content"$_SESSION["frontend_userid"]);
        exit;
    }
    $userid $_SESSION["frontend_userid"];

    $core_permission = array();

    $stmt $db2->prepare("SELECT * FROM patron_user WHERE userid=? AND status='Enable'");
    $stmt->execute(array($userid));
    if (
    $row $stmt->fetch())
    {
        
    $userid $row["userid"];
        
    $username $row["username"];    
        
    $fullname $row["fullname"];
        
    $useremail $row["email"];
        
    $isadmin $row["isadmin"];
        
    $global_user_info $row;
        
        
    // Give user groups
        
    $sql "SELECT * FROM core_usergroup WHERE userid='$userid'";
        
    $stmt $db2->prepare($sql);
        
    $stmt->execute();
        
    $ugroups = array();
        while(
    $row $stmt->fetch()){
            
    $ugroups[] = $row['groupid'];
        }

        
        
    // Give user permissions by groups
        
    $where '';
        if(
    count($ugroups) == 1) { 
            
    $gid $ugroups[0];
            
    $where "groupid='$gid'";
        } elseif(
    count($ugroups) > 1){
            
    $i 1;
            foreach(
    $ugroups as $groupid) {
                if(
    $i == 1) {
                    
    $where .= "groupid='$groupid'";
                } else {
                    
    $where .= " OR groupid='$groupid'";
                }
                
    $i++;
            }
        }
        if(
    $userid == '1') { $where '1=1'; }
        
    $sql "SELECT * FROM tudm_permission WHERE $where";
        
    $stmt $db2->prepare($sql);
        
    $stmt->execute();
        
    $upermissions = array();
        while(
    $row $stmt->fetch()){
            
    $permissionid $row["permissionid"];
            
    $upermissions[$permissionid] = "on";
            
        }
    } else {
        
    $userid 0;
        
    $username 'system';
    }
    $stmt $db2->prepare("INSERT INTO log_site SET requesturi=?, userid=?, datetime=NOW()");
    $stmt->execute(array($_SERVER["REQUEST_URI"], $userid));

    if (
    $_GET["_m"] == "login")
    {
        include 
    "modules/login/module_login.php";
        exit;
    }
    if (
    $userid == 0)
    {
        include 
    "modules/login/module_login.php";
        exit;
    }
    if (
    $_GET["_m"] == "monograph_info")
    {
        include 
    "modules/login/module_monograph_info.php";
        
    auditlogFront("view monograph info"$_SESSION["frontend_userid"]);
        exit;
    }
    if (
    $_GET["_m"] == "monograph_patron")
    {
        include 
    "modules/monograph/module_monograph_patron.php";
        
    auditlogFront("view monograph patron"$_SESSION["frontend_userid"]);
        exit;
    }
    if (
    $_GET["_m"] == "monograph_summaries")
    {
        include 
    "modules/monograph/module_monograph_summaries.php";
        
    auditlogFront("view monograph summaries"$_SESSION["frontend_userid"]);
        exit;
    }
    if (
    $_GET["_m"] == "monograph_history")
    {
        include 
    "modules/monograph/module_monograph_history.php";
        
    auditlogFront("view monograph history"$_SESSION["frontend_userid"]);
        exit;
    }
    if (
    $_GET["_m"] == "borrowed_history")
    {
        include 
    "modules/monograph/module_borrowed_history.php";
        
    auditlogFront("view borrow history"$_SESSION["frontend_userid"]);
        exit;
    }
    if (
    $_GET["_m"] == "patron_profile")
    {
        include 
    "modules/monograph/module_patron_profile.php";
        
    auditlogFront("view profile"$_SESSION["frontend_userid"]);
        exit;
    }
    if (
    $_GET["_m"] == "return_fines")
    {
        include 
    "modules/monograph/module_return_fines.php";
        
    auditlogFront("view return fines"$_SESSION["frontend_userid"]);
        exit;
    }

    include 
    "modules/login/module_login.php";
    exit;

    ?>
    Last edited by SpacePhoenix; Aug 15, 2011 at 23:22. Reason: placed php tags around the php code

  4. #4
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,065
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    Try adding this (after the session_start() line):

    PHP Code:
    echo '<pre'>
    var_dump($_GET);
    echo 
    '</pre>';

    echo 
    '<pre'>
    var_dump($_SESSION);
    echo 
    '</pre>'
    You're probably not setting any values for either the session or query string elsewhere.
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  5. #5
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    your global.inc.php probably is supposed to set up the default values for the get array; the index you've shown us has no checking to see if it's set.


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
  •