Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/173856-undefined-index-warning-in-my-code/
Share on other sites

php evaluates then pushes your html (what you see when you go to a website) How you're approaching this is wrong.. you're looking to push the html THEN have php 'hang' and receive the data they give to you, NOW this is impossible to do.. in order for you to do t his you'd need to create the form.. and with php 'expect' data to be sent back to the same page.. with the data you can do whatever you do with the data.. but you will not push html then get a response in the same execution of php

So I'd have to make a seperate html input form and direct that to a php script that evaluates data, right?

 

but what if i want to do it in the same php form? sry if i missed something. can i shuffle the html code in the welcome function and make it work with a single php script with html?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.