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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jun 2009
    Location
    Atlanta, GA
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question PHP/MySQL Undef. Index Id Error

    Hi,

    Hope you guys are well.

    I am trying to get records to delete from a database. Rather than ramble on, here's the code
    PHP Code:
    <?php
        ob_start
    ();

        
    session_start(); // start a session

        
    echo ini_get('display_errors');
        
        if (!
    ini_get('display_errors')) {
            
    ini_set('display_errors'1);
        }
        
        
    //echo ini_get('display_errors');
        
    error_reporting(E_ALL);
        

        
    //set page title info
        
    $page_name "Delete Store";
        
    $page_id "del";
        

        
    //check if cookie exists
        
    if($_SESSION['login'])
        {
            require_once(
    '../../nada_config.php');        
            require_once(
    '../inc/validation.php');

        }
        else
        {
            
    //send non-authenticated visitor to login page.
            
    header('Location: index.php');    
        }

        
    //PRETTY SURE THE ERROR IS HERE<<<< but how would I know, ya know?
        
    if(isset($_POST['submitted']))
        {
            
    $store_id $_POST['id'];

            if(isset(
    $_POST['id']))
            {
                echo 
    $_POST['id'];
            }
            else 
            {
                echo 
    "No ID set"
            }
            
            
    // prepare to delete record from DB
            
    $sql "DELETE FROM  `lisareis_storesNADA`.`stores_list` WHERE  `stores_list`.`store_id` =" .$store_id;

            
    //option code: DELETE FROM stores_list WHERE store_id =" . $store_id;
            
            
    $myData mysql_query($sql$conn
            OR exit(
    'Unable to delete store listing.');
            
    $row mysql_fetch_assoc($myData);
            
            
    //redirect to edit page
            
    header('Location: edit.php');
            
            }    
            
            else  
    //first time we've visited the page
            
            
    {
                
            
    $store_id $_GET['id'];
            
    $valid verifyNum($store_id);
            
            if(!
    $valid)
            {
                
    $error_msg 'There has been an error selecting the correct store record';
                echo(
    $error_msg);
                echo 
    "<a href='edit.php'>Return to admin edit page and try again.</a>";
            }
            else
            {
                
    //prepare to display selected employee info
                // create sql statement
                
    $query "SELECT * FROM stores_list WHERE store_id = $store_id";
            
                
    //store results of sql query into $myData
                
    $myData mysql_query($query $conn)
                OR exit(
    'Could not select data from database');
            
                
    $row mysql_fetch_assoc($myData);
        
                
    mysql_close($conn);
            }     
        }

    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />    

    <link rel="stylesheet" type="text/css" href="../css/nada-admin.css" />

    <title>Delete Store Listing</title>
    </head>
    <body id="delete">

    <div id="wrapper">
        <div id="header">
            <h1>Admin Section</h1>
            <h2>Delete Store Listing</h2>
        </div><!--end header-->
        <div id="nav">
            <ul>
                <li><a href="add.php" title="add new store">Add Store</a> |</li>
                <li><a href="edit.php" title="edit store">Edit Store</a> |</li>
                <li><a href="<?php $_SERVER['PHP_SELF'?>?log_out=1" title="log out">Logout</a></li>
            </ul>
        </div><!--end nav-->
        <div id="content">
        
        <?php 
        
    echo "<h1>Are you sure you wish to delete this store listing?<br /> This action is permanent.</h1>";
                echo 
    "<ul>";
                echo 
    "<li>".$row['store_id']."</li>";
                echo 
    "<li>".$row['store']."</li>";
                echo 
    "<li>".$row['address']."</li>";
                echo 
    "<li>".$row['city']."</li>";
                echo 
    "<li>".$row['st']."</li>";
                echo 
    "<li>".$row['zip']."</li>";
                echo 
    "<li>".$row['phone']."</li>";
                echo 
    "</ul>";
        
    ?>
            <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" id="del_form">
            <fieldset>
                <legend>Delete Store from Listing</legend>
                <input name="store_id" type="hidden" value="<?php echo $store_id ?>" />
                <input name="store" type="hidden" value="<?php echo $store ?>" />
                <input name="submitted" type="submit" value="YES!! Delete Record" />
                <input name="canceled" type="button" value="NO!! Cancel" onclick="window.location = 'edit.php';" />
            </fieldset>
            </form>
        </div><!--end content-->
        
        <div id="break"></div>
            
        <div id="footer">
            <ul>
                <li><a id="ft_home" href="/index.php">HOME</a></li>|
                <li><a id="ft_about" href="/about.php">ABOUT</a></li>|
                <li><a id="ft_product" href="/product.php">PRODUCTS</a></li>|
                <li><a id="ft_faq" href="/faq.php">FAQ</a></li>|
                <li><a id="ft_store" href="/store.php">STORE</a></li>|
                <li><a id="ft_press" href="/press.php">PRESS</a></li>|
                <li><a id="ft_contact" href="/contact.php">CONTACT </a></li>
            </ul>
            <p>&copy;2011 Nada Beverage Company, Inc.</p>
            <p class="right">Design: Dogwood Agency</p>
        </div><!--end footer-->
        
    </div><!--end wrapper-->
    </body>
    </html>
    The error: Notice: Undefined index: id in /home2/lisareis/public_html/dogwood.nada/admin/delete.php on line 38

    I made a comment in all caps to identify where I think the error is. The reason I think it's there is because when I select the record from the edit page, it takes me to the delete page (code above) and I see the data from the record. The error happens when I submit the form to delete the record. I also get the error print "No ID set" from the if/else statement.

    Is that enough information? Can I provide anything else? I sure do appreciate the help.

    Thanks for your time!!

    Lisa Rose

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    There is no input element named 'id'. The error is actually here: $store_id = $_POST['id']; , and given the line number that would indicate you have whitespace prior to the <?php tags as well.

  • #3
    New to the CF scene
    Join Date
    Jun 2009
    Location
    Atlanta, GA
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    There is no input element named 'id'. The error is actually here: $store_id = $_POST['id']; , and given the line number that would indicate you have whitespace prior to the <?php tags as well.
    OK, I see that but if you notice further down, it uses 'id' in the same manner and is successful at calling the record. Also, I did try it using $_GET & $_REQUEST instead of $_POST, and got the same error. Should I call the record then delete? Is the order off?

    PHP Code:
    $store_id $_GET['id'];
            
    $valid verifyNum($store_id);
            
            if(!
    $valid)
            {
                
    $error_msg 'There has been an error selecting the correct store record';
                echo(
    $error_msg);
                echo 
    "<a href='edit.php'>Return to admin edit page and try again.</a>";
            }
            else
            {
                
    //prepare to display selected store info
                // create sql statement
                
    $query "SELECT * FROM stores_list WHERE store_id = $store_id";
            
                
    //store results of sql query into $myData
                
    $myData mysql_query($query $conn)
                OR exit(
    'Could not select data from database');
            
                
    $row mysql_fetch_assoc($myData);
                
                
    mysql_close($conn);
            } 
    And for clarity, what do you mean when you say 'what space' before the <?php tag? I don't understand what that means.

    Thanks!

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    That is from a $_GET not from a $_POST.
    I cannot see if $_GET['id'] exists in this context. The form action is what governs that, and given what you have here will only be checked if $_POST['submitted'] is not set (keeping in mind that IE will not guarantee a successful field on an input submit despite being a standard).

    Given what you have here, id is sent via $_GET to the page, which shows the record and asks for verification to delete. You then execute the deletion if confirmed.
    PHP_SELF does not include the querystring (at least I'm pretty sure it doesn't and I cannot test here). So there is no $_GET['id'] being passed. If I had to bet, you want to pull from $_POST['store_id'].

    As for space, I mean that <?php is not the first line of code (according to this error).

  • #5
    New to the CF scene
    Join Date
    Jun 2009
    Location
    Atlanta, GA
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    You are a bloody genius! Thank you so much! Not only do I see the error but I actually understand why it was wrong!

    Thank you a million times over!

    Lisa


  •  

    Posting Permissions

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