1

I try to define an array, but although having read all of the suggestion here, I still got an error notice when execute.

My form consist among everything else, field min which define the number of textareas in

<input type="text" name="min[1]">

My PHP file has:

<?php
$min = $_POST['min'];
$area = array();

for($j=1; $j=<$length; $j++) {
if($_POST['row'][$j] != "") {

    if(($_POST['min'][$j])!="") {
    for($k=1;$k<=$min[$j];$k++) {
    $area[$j] .= '<textarea name="label'.$j.$k.'" rows="3"' ></textarea>';
    }}
    if(($_POST['min'][$j])=="") {
    $area[$j] = '<textarea name="label'.$j.$k.'" rows="3"'" ></textarea>';
    }
    $blah .= $j.') '.$row[$j].'<br/>'.$area[$j].'<div id="inner'.$j.'"></div><br/><br/>';
}}

I can see that the problem is in array, because the script try to locate the keys which are not there. So how to defne this in advance... This works but it's no solution as you can se:

$area = array("","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",);
2
  • Your code isn't syntactically valid. It should be clear from coloration of this post itself. Commented Mar 29, 2014 at 19:04
  • It is pretty easy. Al of the variables, or actually all of the $_POST methods are called on the simple input text fields. SO, min and row are actually input fields. Commented Mar 29, 2014 at 19:06

2 Answers 2

1

You need to check if that array element exists before you check its value.

Change

if(($_POST['min'][$j])!="") {

to

if(isset($_POST['min'][$j]) && $_POST['min'][$j])!="") {
Sign up to request clarification or add additional context in comments.

1 Comment

Actually didn't work in my case. The problem is in array $area. Because it is not defined by $_POST['min']. It should be defined somehow in the loop, but I don't know how
0

$length is not initialized...

In PHP the first array index is 0.

You could iterate through array with the foreach operator.

If you copy $_POST['min'] in $min , use it. stop using $_POST['min'] it's confusing.

1 Comment

@user3244442 There is probably other problems with your code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.