I have a web page that contains a few forms. Form1 lets the user enter text into a few input boxes. Once the submit button is clicked, the info is displayed in a textarea in form2. The info is displayed in the following format:
Inputbox1|| Inputbox2|| Inputbox3|| Inputbox4|| Inputbox5
The user can then manually add or edit the info (must be in the format above) and click on the submit button in form2 which will save the info to a flat file. Each time the user accesses this page, the info will be displayed in form2.
The problem I am running into is a Notice: Undefined variable: myAray and Undefined array: myAray error. This happens if a user skips form1 or deletes all of the data in the textarea in form2 and then clicks the submit button in form2 to save/create the empty flat file. It is because the array and/or variable is empty. Other than that, the page works fine with no errors.
Here is the code that causes the errors:
foreach ($myAray as $ary) {
$crSrg .= "array(\"" . $ary[0] . "\", \"" . $ary[1] . "\", \"" . $ary[2] . "\", \"" . $ary[3] . "\", \"" . $ary[4] . "\", \"" . $ary[5] . "\"), ";
}
If I change it to the following, the Undefined array: myAray error goes away, but the Undefined variable: myAray error remains:
if(is_array( $myAray)){
foreach ($myAray as $ary) {
$crSrg .= "array(\"" . $ary[0] . "\", \"" . $ary[1] . "\", \"" . $ary[2] . "\", \"" . $ary[3] . "\", \"" . $ary[4] . "\", \"" . $ary[5] . "\"), ";
}
}
If I change it to the following, I get no errors, but the text that a user adds to the textarea in form2 is not saved when the submit button is clicked. The text area box just goes blank after the submit button is clicked:
if( isset( $_POST['myAray'] ))
$cnAry = $_POST['myAray'];
else
$myAray = '';
if(is_array( $myAray)){
foreach ($myAray as $ary) {
$crSrg .= "array(\"" . $ary[0] . "\", \"" . $ary[1] . "\", \"" . $ary[2] . "\", \"" . $ary[3] . "\", \"" . $ary[4] . "\", \"" . $ary[5] . "\"), ";
}
}
I guess what I need to do, is to print or echo an error message, instead of having the blank textarea being saved, when a user tries to submit form2 with a blank textarea.
I'm sure it's a simple fix, but I can't figure it out.
Any ideas?