Should I use an array in a form / how?

This is a discussion on Should I use an array in a form / how? within the PHP General forums, part of the PHP Programming Forums category; I am programming a form this morning.* I don't understand arrays really well.* I think this is what I ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-16-2007
ron.php
 
Posts: n/a
Default Should I use an array in a form / how?

I am programming a form this morning.* I don't understand arrays really well.* I think this is what I am needing to use, but I am really not sure.

I have a PHP script that checks a POP e-mail address and is suppose to take the incoming message and save it to a mySQL table based on the subject line.* Every now and then the subject line is broken with something like a <br /> and so I have a handful of messages that need to be indexed manually.* IE my script can't see a "Subject: Correspondence for message 123" --- it is being received as "Subject: Correspondence for <br />message 123"* I am trying to update the mySQL table with a form instead of continuing to use phpmyadmin to do these updates.* That is the background for my current project.*

What I am wanting to do in my form is call up all the incoming messages that have a message value of 0*(where they weren't automatically indexed) and I can read through the incoming message to see what their reference number is and type it in the field that I have called
"new_correspondence_received".* An example of my HTML code is below.

Where I am getting stuck is I have more than 1 message that wasn't indexed automatically I am not sure how to retrieve the values of: correspondence_reference*and new_correspondence_reference.* (The only reason I am displaying correspondence_received is to look for the reference number)* Can what I am trying to do be accomplished through an array to find out the values submitted?* How do you make array variables?* What changes need to be made to my form so I can find out the values being submitted?

Each message received that isn't automatically index is dispayed through this form, one <TR></TR> per message.* I know the mysql commands to update the table, I just need help to retrieve the form variable values.**Thanks for your help.* Ron

<tr><td width=200>
<font face="times new roman">
<center>
<input id=all type="checkbox" name="correspondence_reference" value="172" checked>
172
</center>
</td><td width=200>
<font face="times new roman">
<center>
<input type=text name="new_correspondence_reference" size=6 maxlength=30 value = "0">
</center>
</td><td width=400>
<textarea COLS=50 ROWS=10 name="correspondence_received">Message here</textarea>
</td></tr>



Reply With Quote
  #2 (permalink)  
Old 10-16-2007
Philip Thompson
 
Posts: n/a
Default Re: [PHP] Should I use an array in a form / how?

On 10/16/07, ron.php <ron.php@actsministries.org> wrote:
>
> I am programming a form this morning. I don't understand arrays really
> well. I think this is what I am needing to use, but I am really not sure.
>
> I have a PHP script that checks a POP e-mail address and is suppose to
> take the incoming message and save it to a mySQL table based on the subject
> line. Every now and then the subject line is broken with something like a
> <br /> and so I have a handful of messages that need to be indexed manually.
> IE my script can't see a "Subject: Correspondence for message 123" --- it is
> being received as "Subject: Correspondence for <br />message 123" I am
> trying to update the mySQL table with a form instead of continuing to use
> phpmyadmin to do these updates. That is the background for my current
> project.



You can strip the <br/> from the string using:

$string = str_replace ('<br/>', '', $string);

What I am wanting to do in my form is call up all the incoming messages that
> have a message value of 0(where they weren't automatically indexed) and I
> can read through the incoming message to see what their reference number is
> and type it in the field that I have called
> "new_correspondence_received". An example of my HTML code is below.
>
> Where I am getting stuck is I have more than 1 message that wasn't indexed
> automatically I am not sure how to retrieve the values of:
> correspondence_referenceand new_correspondence_reference. (The only reason I
> am displaying correspondence_received is to look for the reference number)
> Can what I am trying to do be accomplished through an array to find out the
> values submitted? How do you make array variables? What changes need to be
> made to my form so I can find out the values being submitted?
>
> Each message received that isn't automatically index is dispayed through
> this form, one <TR></TR> per message. I know the mysql commands to update
> the table, I just need help to retrieve the form variable values.Thanksfor your help. Ron
>
> <tr><td width=200>
> <font face="times new roman">
> <center>
> <input id=all type="checkbox" name="correspondence_reference" value="172"
> checked>
> 172
> </center>
> </td><td width=200>
> <font face="times new roman">
> <center>
> <input type=text name="new_correspondence_reference" size=6 maxlength=30
> value = "0">
> </center>
> </td><td width=400>
> <textarea COLS=50 ROWS=10 name="correspondence_received">Message
> here</textarea>
> </td></tr>



To make an array in an HTML form...

<input type="checkbox" name="correspondence_reference[172]" value="1"
checked /> 172
<input type="checkbox" name="correspondence_reference[173]" value="1" /> 172
<input type="checkbox" name="correspondence_reference[174]" value="1" /> 172
....

Do that for each reference value. Then, in your PHP when you're grabbing the
POST data, you can just loop through the array to see what's been "checked"
- actually, only the "checked" items will show in the array. So, let's say,
from above, the 172 and 174 checkboxes were checked, the POST array would
contain the following...

<?
foreach ($_POST['correspondence_reference'] as $index => $value) {
echo "$index => $value";
}
?>

// Output
172 => 1
174 => 1

It doesn't really matter what the "value" of the checkboxes are. As long as
you know the index, then you're good and you can use that information
appropriately. This is one approach. I know there are others though...

Good luck,
~Philip

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 01:27 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0