PHP and MySQL Mailout

Soldato
Joined
28 Apr 2011
Posts
14,795
Location
Barnet, London
Can anyone give me some pointers on the best way to do this.

I have a table with people in with the usual details, including an email address, their name and a unique key.

At the moment I'm setting up a form, iterating through the table displaying their name and a tick box, the id being the unique key.

Code:
while($row = mysqli_fetch_array($result)) {
                        $team=strtolower($row['team']);

                        if($row['email'] == "") {
                            $team = 'white';
                        }

                        ?>
                        <div class="col-sm-30 <?php echo $team.'Background'; ?>">
                            <input class="form-group-input" type="checkbox" value="<?php echo $row['uniqueid']; ?>" name="<?php echo $row['uniqueid']; ?>" id="<?php echo $row['uniqueid']; ?>" <?php if($team == 'white') { echo 'disabled'; } ?>>
                            <label class="form-checkbox form-label-inlin" for="<?php echo $row['uniqueid']; ?>">
                            <?php echo checkPartnerName($row['uniqueid']); ?>
                            </label>
                        </div>
                        <?php
                    }

When it then posts, how am I best to go through getting the people's details? Can I iterate through $_POST?

Does that all make sense?

I'm sure there's a better way to do this though, I just don't know how?
 
Caporegime
Joined
28 Jan 2003
Posts
39,874
Location
England
What exactly are you trying to do?

Is this just a visual thing of who has been sent an email or when you manually tick the box it sends them an email?
 
Soldato
Joined
28 Oct 2006
Posts
12,456
Location
Sufferlandria
When it then posts, how am I best to go through getting the people's details? Can I iterate through $_POST?

Don't use the $_POST to send the details, that could be manipulated. Post a list of the uniqueid values from the selected checkboxes then go and retrieve the email addresses from the database for each id.
 
Soldato
OP
Joined
28 Apr 2011
Posts
14,795
Location
Barnet, London
Thanks for the replies.

What exactly are you trying to do?

Is this just a visual thing of who has been sent an email or when you manually tick the box it sends them an email?

It brings a list of everyone in the database. You tick ones you want to receive the email. Press submit and they all get sent an email.

Don't use the $_POST to send the details, that could be manipulated. Post a list of the uniqueid values from the selected checkboxes then go and retrieve the email addresses from the database for each id.

Yes, that's what I'm doing above, although I'm asking if I can iterate through $_POST to do so. Is there a better way to do it? Are you saying I can/should send them all in one post and then split them back up and iterate on the next page?
 
Soldato
Joined
28 Oct 2006
Posts
12,456
Location
Sufferlandria
Yes, that's what I'm doing above, although I'm asking if I can iterate through $_POST to do so. Is there a better way to do it? Are you saying I can/should send them all in one post and then split them back up and iterate on the next page?

Ah, i see.

In that case, no. You can't iterate through $_POST, you can only post one object per request.
That object can be an array of other objects, so you can post everything at once but you'd iterate through an attribute of $_POST rather than the post object itself eg. "foreach($_POST->customerarray as customer)" rather than "foreach($_POST as customer)"

It could also be done with a separate post for each checkbox. So every time you tick a box, it fires off a single post request to email that customer. Probably not good UI for this scenario as there'd be no way to undo it if you ticked a box by mistake.
 
Soldato
OP
Joined
28 Apr 2011
Posts
14,795
Location
Barnet, London
Okay thanks, so I guess I would use some Javascript to collect the uniqueid's of everything that is ticked when submit is clicked, put them all into an array, then post the array?
 
Soldato
Joined
28 Oct 2006
Posts
12,456
Location
Sufferlandria
Okay thanks, so I guess I would use some Javascript to collect the uniqueid's of everything that is ticked when submit is clicked, put them all into an array, then post the array?

Yep, I would use java to do it but I think it could also be done in just php+html. I can't remember how exactly to do it but you can group the checkboxes together (possibly just name them all the same?) and it'll submit an array of values from all the checkboxes.
 
Back
Top Bottom