Re: [PHP] looping through a $_POST variable
- From: php@xxxxxxxxxxxxxxx (Mark Kelly)
- Date: Mon, 31 Dec 2007 04:39:55 +0000
Hi.
On Monday 31 December 2007 00:34, Richard Kurth wrote:
When I do a var_dump($_POST['emails']); it has all the emails in it
string(65) "rkurth@xxxxxxxxxxxxxx ckurth@xxxxxxxxxxxxxx
tkurth@xxxxxxxxxxxxxx"
Then this simple regex should do you; just use it instead of explode:
$AddressList = preg_split('/\s+/', $_POST['emails']);
I will validate the emails after I get the loop to work
An better idea might be to do that INSIDE the loop (the following assumes
your $memberid is a number, adjust to suit if this is not the case):
foreach ($AddressList as $emailaddress) {
// Escape the data before letting it near the db
$SAFE_emailaddress = mysql_real_escape_string($emailaddress);
$SAFE_memberid = intval($_POST["members_id"]);
// Build the query
$sql = "SELECT id
FROM contact
WHERE emailaddress = '$SAFE_emailaddress'
AND members_id = '$SAFE_memberid'";
// etc. etc.
}
safe_query is a function that I call that does query stuff
That is a *terrible* name for that function, as it does nothing at all to
make the query safe. You might consider renaming it to run_query or
something. Remember, other people may have to make sense of your code one
day.
Hope this helps,
Mark
.
- References:
- looping through a $_POST variable
- From: Richard Kurth
- Re: [PHP] looping through a $_POST variable
- From: "Richard Lynch"
- Re: [PHP] looping through a $_POST variable
- From: Richard Kurth
- looping through a $_POST variable
- Prev by Date: why is <option '97' selected>Japan</option> not highlighted
- Next by Date: Re: [PHP] why is <option '97' selected>Japan</option> not highlighted
- Previous by thread: Re: [PHP] looping through a $_POST variable
- Next by thread: [PHP] Re: [BULK] [PHP] I'm trying to sending an image via email
- Index(es):