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
    Sep 2009
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Undefined index warning in my code

    Im trying to build my own website and here is my first php script ever!! Im trying to get the input and process it in the same page. The welcome function shall ask for the input with the no. of entries and it shall load such many times the text fields for further input.

    I get this error when i run it

    Notice: Undefined index: seen in C:\wamp\www\sast.com\ded.php on line 46
    and when i enter the data and all, the text fields come up but with these warnings again
    Notice: Undefined index: ecarray in C:\wamp\www\sast.com\ded.php on line 64

    Notice: Undefined index: amtarray in C:\wamp\www\sast.com\ded.php on line 65
    PHP Code:
    <?php
    $go 
    welcome();
    function 
    welcome(){
    ?>
    <h1>
    Select the area, month and the no. of records you want to enter<br>
    </h1>
    <form method="post">
    <select name="area" single>
    <option>----Area</option>
    <option>corp</option>
    <option>kgm</option>
    <option>yld</option>
    <option>mng</option>
    <option>rg1</option>
    <option>rg2</option>
    <option>rg3</option>
    <option>bhpl</option>
    <option>mm</option>
    <option>bpa</option>
    <option>srp</option>
    <option>hyd</option>
    </select>
    <select name="month" single>
    <option>----Month</option>
    <option>jan</option>
    <option>feb</option>
    <option>mar</option>
    <option>apr</option>
    <option>may</option>
    <option>jun</option>
    <option>jul</option>
    <option>aug</option>
    <option>sep</option>
    <option>oct</option>
    <option>nov</option>
    <option>dec</option>
    </select>
    <div>
    <input type="text" name="entries" value="No. of entries" onfocus="this.value=''">
    </div>
    <br>
    <input type="submit" name="seen">
    </form>
    <?php
    $gone 
    $_REQUEST["seen"];
    return 
    $gone;
    }
    if(
    $go)
    getdata();
    # function to load form to get empcode and amount
    function getdata(){
    $area $_REQUEST["area"];
    $month $_REQUEST["month"];
    $entries $_REQUEST["entries"];
    for(
    $i=0;$i<$entries;$i++)
    {
    ?>
    <form method="post">
    <div><input type="text" name="ecarray" value="employee code" onfocus="this.value=''"</div>&nbsp&nbsp&nbsp
    <div><input type="text" name="amtarray" value="deduction amount" onfocus="this.value=''"></div>&nbsp&nbsp&nbsp
    </form>
    <?php
    $ecarray
    [] = $_REQUEST["ecarray"];
    $amtarray[] = $_REQUEST["amtarray"];
    }
    echo 
    "<form><input type='submit' value='submit'/><br></form>";
    }
    ?>

    Any help will be great. Sorry if this is so noobish. But i just started learning.

  • #2
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Here's the issue:
    PHP Code:
    $gone $_REQUEST["seen"]; 
    Does the aforementioned indexes exist in either $_POST, $_GET, or $_COOKIE?

    Check for their existence with isset() first:
    PHP Code:
    $gone = isset( $_REQUEST['seen'] ) ? $_REQUEST['seen'] : NULL
    Last edited by kbluhm; 09-11-2009 at 04:19 AM.

  • #3
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    okay that worked.
    now, how can i get a html array to be stored in php array?

    regards..

  • #4
    Regular Coder Zangeel's Avatar
    Join Date
    Oct 2007
    Location
    public_html/
    Posts
    638
    Thanks
    17
    Thanked 79 Times in 79 Posts
    An HTML array? as in name="array[]" ??

    Use post data with a form, then

    $_POST["array"] because the new array. So you can access it's values like

    PHP Code:
    var_dump($_POST["array"]); // outputs array structure 

    print $_POST["array"][0]; // first array value
    print $_POST["array"][1]; // second array value ... 
    PHP Code:
    $aString is_string((string)array()) ? true false// true :D 
    [/CENTER]

  • #5
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Zangeel View Post
    An HTML array? as in name="array[]" ??

    Use post data with a form, then

    $_POST["array"] because the new array. So you can access it's values like

    PHP Code:
    var_dump($_POST["array"]); // outputs array structure 

    print $_POST["array"][0]; // first array value
    print $_POST["array"][1]; // second array value ... 
    okay lemme see. thanks for the help


  •  

    Posting Permissions

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