|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi there!
This is probably going to seem like a pretty easy question... but I'm just learning all this and coud really use some help. I'm creating a form that sends an email to a bunch of people. The email addresses are stored in a database and I need them to be transferred through to the form. Now.. the form submits to a perl script that takes care of the emailing so the email addresses just need to be in a string.. but how do I get them into a string when they are in an array? Here is my code.. <?php include("open_db.inc"); $cust=mysql_query("SELECT email_address FROM wip ORDER BY email_address ASC "); if (!$cust) { echo("<P>Error fetching company details: " . mysql_error() . "</P>"); exit(); } $cust = mysql_fetch_array($cust); $wipemailaddresses = $cust["email_address"]; ?> -- and here is the form field in question.. -- <input type="hidden" name="r_bcc" value="<?php echo ($wipemailaddresses); ?>" > -- This only outputs the first email address in the table. I've tried using the implode function but this just seems to repeat the email address.. so yeah I am stuck!! Any help would be greatly appreciated! Happy New Year! -Craig "...Expect the Unexpected..." |
|
#2
|
|||
|
|||
|
Re: Importing results from databse into form
Quote:
Erm, well, exactly how does the form pass the info to the perl script? If I was doing this, I'd probably do something like: while($cust) { mail(values here, so that it cycles through the array emailing them) } Though maybe someone more experienced will spot an error in my method. EDIT: PHP Code:
ah, just noticed, that will also just assign the *first* value in the array to $wipemailaddress. Last edited by Kanu : December 31st, 2002 at 10:51 AM. |
|
#3
|
|||
|
|||
|
The reason it's only assigning the first value is because you're not looping through your result set... Try this:
PHP Code:
This will loop through the entire result set, which contains all the addresses extracted from your SQL query. I noticed you said that the email addresses will be passed as one string... What will be your delimiter for the addresses? Whatever it is, use this in your appending code: PHP Code:
Hope that helps!
__________________
____________________________________________ Developer Shed Weekly Writer | DevArticles Forum Moderator Build Your Own KlipFolio Klip With PHP FrankManno.com - Under Construction Design Interactive Group - Under Construction |
|
#4
|
|||
|
|||
|
Hey guys!
Thanks so much for your responses, muchly appreciated!! I'll try it out now and let you know how it goes... Happy New Years! -Craig |
|
#5
|
|||
|
|||
|
OK I must be doing this totally wrong... I've tried the following:
PHP Code:
All this gives is parse errors.. I'm guessing my While loop is somehow incorrect (not terminating it correctly?). I know that this does work: PHP Code:
So it seems to be something in the while loop. Maybe I'm going about this the wrong way? All I want to do is get some email addresses from a database and pass them to a hidden field in the form. Is using an array the correct way of going about this? I feel like I'm nearly there... but not quite. I'll have another play around but if anyone has anymore suggestions I'd be most happy to read them. Thanks guys and girls! |
|
#6
|
|||
|
|||
|
Ok I've now tried the below and am getting a parse error:
PHP Code:
Parse error is occuring on the mysql_query line (but it works when I don't have the while loop..) Arrg :/ |
|
#7
|
|||
|
|||
|
What's the exact error message you're getting?
Although I don't see it being the problem, I would strongly recommend using different variable names for your query and resultset. You're using $cust for both, whereas, it would be better to use different names: PHP Code:
|
|
#8
|
|||
|
|||
|
Hi there Frankie,
I did as you suggested and the same error appears. The error message is as follows: Parse error: parse error, expecting `','' or `';'' in /home/httpd/html/db/omt/wip/wipemailtest_1.php on line 9 It doesn't make sense as there seems to be a , or ; in all the correct places... maybe I am just missing something... PHP Code:
Line 9 is the $cust = mysql_query("SELECT email_address FROM wip ORDER BY email_address ASC"); |
|
#9
|
|||
|
|||
|
Oops.. fixed up the ; error but still getting a parse error:
Parse error: parse error in /home/httpd/html/db/omt/wip/wipemailtest_1.php on line 13. Line 13 is the exit line - exit(); PHP Code:
|
|
#10
|
|||
|
|||
|
Looks good although I use exit like this,
PHP Code:
Atleast that works for me.
__________________
Thanks, Attila http://www.glorynaspiration.com http://www.abitofthings.com |
|
#11
|
|||
|
|||
|
Quote:
PHP Code:
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > Importing results from databse into form |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|