Link to home
Start Free TrialLog in
Avatar of Shamsul Kamal
Shamsul Kamal

asked on

PHP form textarea array submission

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.

Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

"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.

Avatar of Shamsul Kamal
Shamsul Kamal

ASKER

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 ?

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>
I think may be because of :

 WHERE invoiceid='$invoiceid'

It can find the $invoiceid .

Any idea how to extract it from my form above ?
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)
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 ?
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i endup doing other way around .. separating checkbox and remarks form.