PHP form textarea array submission

Shamsul Kamal
Shamsul Kamal used Ask the Experts™
on
Hi,

I would like to request an assistant.

I have the following textarea form , which is generated as array by php :

<textarea name='remark[]' id=$invoiceid cols='10' rows='1'>
</textarea>
<input type='submit' value='Go' name='SubmitRemark'>


I use the following PHP scripts to record :


if(isset($_POST['SubmitRemark'])){
$textareaarray=$_POST['remark'];
$invoiceid=$_POST['invoiceid'];
foreach($textareaarray as $textarea) {
$sql=mysql_query("UPDATE domainorder SET remark='$textarea', datepaid=NOW() WHERE invoiceid='$invoiceid' " , $conn);
if($sql){echo "<p><font face='Arial'><b>Domain DB Updated</b></font></p>";}}}


It seems the above php script not able to capture the post data and not record in the mysql.

Can anybody help to check and provide the complete new php scripts to handle textarea array ?

Appreciates anybody assistant.


Thank you.

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Dave BaldwinFixer of Problems
Most Valuable Expert 2014

Commented:
"name='remark[]'" only works if you have more than one <textarea> with that name.  A single <textarea> is not an array, it's just a string.
quick glance looks like that should work.

try the some helpful functions to troubleshoot

EG. var_dump()

comment out the db transactions using //

before the foreach try a vardump($textareaarray);
before the foreach try a vardump($invoiceid);

this will let you know if it is correctly collecting the values in the POST.

You can also covert your form from POST to GET to see the values in the url while your testing.

Shamsul KamalJunior Tech

Author

Commented:
The following is the output of var_dump($textareaarray);

array(98) {
  [0]=>
  string(5) "sdasd"
  [1]=>
  string(0) ""
  [2]=>
  string(0) ""
}


var_dump($invoiceid); return NULL .

Any hints ?

Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Shamsul KamalJunior Tech

Author

Commented:
The above is the var_dump output , the following is the actual form :


<td>9</td>
            <td>63350</td>
            <td align='left'>smarttopup.biz</td>
            <td><font color=green>Yes</font></td>
            <td>1</td>
            <td><font color=red><b>Unpaid</b></font></td>
            <td>0000-00-00 00:00:00</td>
            <td>&nbsp; <input type='checkbox' name='checkbox[]' id='checkbox[]' value='63350'></td>
            <td>&nbsp; <textarea name='remark[]' id=63350 cols='10' rows='1'></textarea><input type='submit' value='Go' name='SubmitRemark'></td>
      
      </tr><tr>
            <td>10</td>
            <td>61532</td>
            <td align='left'>clubasterianetwork.com</td>
            <td><font color=green>Yes</font></td>
            <td>1</td>
            <td><font color=red><b>Unpaid</b></font></td>
            <td>0000-00-00 00:00:00</td>
            <td>&nbsp; <input type='checkbox' name='checkbox[]' id='checkbox[]' value='61532'></td>
            <td>&nbsp; <textarea name='remark[]' id=61532 cols='10' rows='1'></textarea><input type='submit' value='Go' name='SubmitRemark'></td>
      
      </tr><tr>
            <td>11</td>
            <td>53681</td>
            <td align='left'>ezytravel.net</td>
            <td><font color=green>Yes</font></td>
            <td>1</td>
            <td><font color=red><b>Unpaid</b></font></td>
            <td>0000-00-00 00:00:00</td>
            <td>&nbsp; <input type='checkbox' name='checkbox[]' id='checkbox[]' value='53681'></td>
            <td>&nbsp; <textarea name='remark[]' id=53681 cols='10' rows='1'></textarea><input type='submit' value='Go' name='SubmitRemark'></td>
      
      </tr><tr>
Shamsul KamalJunior Tech

Author

Commented:
I think may be because of :

 WHERE invoiceid='$invoiceid'

It can find the $invoiceid .

Any idea how to extract it from my form above ?
Shamsul KamalJunior Tech

Author

Commented:
I think may be because of :

 WHERE invoiceid='$invoiceid'

It can't find the $invoiceid .

Any idea how to extract it from my form above ?
Because you should extract a POST value from the name attribute, not id

$invoiceid=$_POST['remark'];
(and change the remark[] to remark)
Shamsul KamalJunior Tech

Author

Commented:
But if i change remark[] to remark it will no longer support array right ?

And how to capture the invoiceid from there as textarea value is something else ?
Fixer of Problems
Most Valuable Expert 2014
Commented:
Are you submitting all of them at once?  The 'id' of the <textarea> will not be part of the POST data, you won't see it.  In addition, submitting all of it as an array will probably end up with things out of sequence because blank fields are not submitted.  A blank in the middle of the page will put everything out of sync.

You need a better plan.
Right - you need only one submit at the bottom, after all textareas.
Shamsul KamalJunior Tech

Author

Commented:
i endup doing other way around .. separating checkbox and remarks form.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial