...

View Full Version : Undefined index warning in my code



ilight
09-11-2009, 02:40 AM
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
$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.

kbluhm
09-11-2009, 04:16 AM
Here's the issue:


$gone = $_REQUEST["seen"];


Does the aforementioned indexes exist in either $_POST, $_GET, or $_COOKIE?

Check for their existence with isset() first:


$gone = isset( $_REQUEST['seen'] ) ? $_REQUEST['seen'] : NULL;

ilight
09-11-2009, 05:23 AM
okay that worked.
now, how can i get a html array to be stored in php array?

regards..

Zangeel
09-11-2009, 06:47 AM
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



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

print $_POST["array"][0]; // first array value
print $_POST["array"][1]; // second array value ...

ilight
09-11-2009, 09:36 AM
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



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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum