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.

PHPMySQL ServerHTML

Avatar of undefined
Last Comment
Shamsul Kamal
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.
Avatar of Tyler Laczko
Tyler Laczko
Flag of Canada image

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 ?

Avatar of Shamsul Kamal
Shamsul Kamal

ASKER

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>
Avatar of Shamsul Kamal
Shamsul Kamal

ASKER

I think may be because of :

 WHERE invoiceid='$invoiceid'

It can find the $invoiceid .

Any idea how to extract it from my form above ?
Avatar of Shamsul Kamal
Shamsul Kamal

ASKER

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)
Avatar of Shamsul Kamal
Shamsul Kamal

ASKER

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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Shamsul Kamal
Shamsul Kamal

ASKER

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

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo