-1

I'm new in PHP developing.

I have a looping textbox

$i = 0;
while($row_recordset = mysql_fetch_array($query_run)) 

{
    echo "<tr>";

    echo "  <td>{$row_recordset['REGNO']}</td>
            <td>{$row_recordset['NAME']}</td>

            <td><input type='text' name='atten_ave".$i."'></td>

         ";

    echo "</tr>";

$i++;

 }

and as you can see I assign a different names in the textbox via array.

I want to echo the value of the textbox into another page to check if it submit the data before I insert it into the database, But there is an error after I execute the page.

$atten_ave = $_POST['atten_ave'.$i];

echo $atten_ave;

Here's the error

Notice: Undefined variable: i in BLAH BLAH BLA

Notice: Undefined index: atten_ave in BLAH BLAH BLAH

I already change the error_reporting in php.ini and set the E-NOTICE

But the error still exist.

I also try to suppress notice errors by putting '@' before the $atten_ave = $_POST['atten_ave'.$i]. But there is no value that was submitted, even I input a value at the textbox.

halfer
  • 19,824
  • 17
  • 99
  • 186
zeus2026
  • 131
  • 13
  • print_r($_POST); and tell what is the output – Vimalnath Apr 26 '13 at 06:07
  • 1
    this has already been answered: http://stackoverflow.com/questions/3314567/how-to-get-form-input-array-into-php-array – rx80 Apr 26 '13 at 06:07
  • possible duplicate of [PHP: "Notice: Undefined variable" and "Notice: Undefined index"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – NullPoiиteя Apr 26 '13 at 06:11
  • @vimalnath Array ( [atten_ave0] => [atten_ave1] => [atten_ave2] => [atten_ave3] => [atten_ave4] => [atten_ave5] => [atten_ave6] => [atten_ave7] => [atten_ave8] => ) – zeus2026 Apr 26 '13 at 06:24
  • oops array values are empty! – Vimalnath Apr 26 '13 at 06:47
  • thanks anyway i use this $i = 0; foreach ($_POST as $textboxname => $values) { echo 'Primary=' .$textboxname. ' ------------ ' . 'Values='.$values; echo '
    '; $i++; }
    – zeus2026 Apr 26 '13 at 08:06

2 Answers2

1

That is correct error, because after submitting the form you don't have a variable $i. You need to loop the $_POST variable like this

$i = 0;
foreach ($_POST as $val) {
   $atten_ave  = $val.$i;
   $i++;
}
chandresh_cool
  • 11,753
  • 3
  • 30
  • 45
  • Hi thanks for the reply, what If sir I have a 3 or more textbox? how can I decalre the given textbox name at the post method. ex$i = 0 foreach ($_POST(WHAT SHOULD I DO HERE?) as $val) { $atten_ave = $val.$i; $i++; } – zeus2026 Apr 26 '13 at 06:51
  • int that case give text field name for each like this foreach($_POST['filedname'] as $val) { $variablenam = $val.$i;} something like this – chandresh_cool Apr 26 '13 at 06:54
  • $chandresh_cool thanks sir for the reply, but in my fieldname I set the names into array to give different name in every textbox, for example the '$i' is auto incrementing, what should I declare at the ($_POST[''] as $val)? I try this but $_POST['atten_ave'.$i] it gives me a error " Invalid argument supplied for foreach()" – zeus2026 Apr 26 '13 at 07:07
  • if you have only this then just give this foreach($_POST as $val) {$atten_ave = $val.$i; $i++; } – chandresh_cool Apr 26 '13 at 07:09
  • put semicolan on first line. i mean $i=0; – Boopathi Rajan Mar 25 '14 at 09:46
0

Another thing: if you close your eyes, you can't see things around you but it doesn't mean they are not there. You are trying the same with notices: you try to hide them instead of get rid of them...

ljubiccica
  • 480
  • 3
  • 17