General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 31st, 2002, 03:48 AM
craigyd craigyd is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Sydney, Australia
Posts: 6 craigyd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to craigyd Send a message via Yahoo to craigyd
Question Importing results from databse into form

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..."

Reply With Quote
  #2  
Old December 31st, 2002, 10:49 AM
Kanu Kanu is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 91 Kanu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Re: Importing results from databse into form

Quote:
Originally posted by craigyd
Hi there!

PHP Code:
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..."


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:
 $wipemailaddresses $cust["email_address"]; 


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.

Reply With Quote
  #3  
Old January 2nd, 2003, 12:43 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
The reason it's only assigning the first value is because you're not looping through your result set... Try this:

PHP Code:
while ($cust mysql_fetch_array($cust)){

$wipemailaddresses .= $cust["email_address"]; 


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:
 $wipemailaddresses .= $cust["email_address"] . "[delimiter]"



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

Reply With Quote
  #4  
Old January 3rd, 2003, 12:49 AM
craigyd craigyd is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Sydney, Australia
Posts: 6 craigyd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to craigyd Send a message via Yahoo to craigyd
Talking Thanks!

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

Reply With Quote
  #5  
Old January 3rd, 2003, 03:51 AM
craigyd craigyd is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Sydney, Australia
Posts: 6 craigyd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to craigyd Send a message via Yahoo to craigyd
OK I must be doing this totally wrong... I've tried the following:

PHP Code:
 $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);

while*($cust*=*mysql_fetch_array($cust)) {



$wipemailaddresses .= $cust["email_address"] . ",";
  } 


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:
 $cust mysql_fetch_array($cust);

   
$wipemailaddresses .= $cust["email_address"] . ","


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!

Reply With Quote
  #6  
Old January 3rd, 2003, 04:38 AM
craigyd craigyd is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Sydney, Australia
Posts: 6 craigyd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to craigyd Send a message via Yahoo to craigyd
Ok I've now tried the below and am getting a parse error:

PHP 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();
}
$wipemailaddresses "";
while*($cust*=*mysql_fetch_array($cust)) {
  
$wipemailaddresses .= $cust["email_address"];
  
$wipemailaddresses .= ", ";
}
 
  
?>


Parse error is occuring on the mysql_query line (but it works when I don't have the while loop..)

Arrg :/

Reply With Quote
  #7  
Old January 5th, 2003, 05:23 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
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:
 $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();
}
$wipemailaddresses "";
while (
$row mysql_fetch_array($cust)) {
  
$wipemailaddresses .= $row['email_address'];
  
$wipemailaddresses .= ", ";


Reply With Quote
  #8  
Old January 6th, 2003, 01:16 AM
craigyd craigyd is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Sydney, Australia
Posts: 6 craigyd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to craigyd Send a message via Yahoo to craigyd
Post

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:
<?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();
}
$wipemailaddresses "";
while*($row*=*mysql_fetch_array($cust)) {
  
$wipemailaddresses .= $row["email_address"];
  
$wipemailaddresses .= ", ";
}
?>


Line 9 is the $cust = mysql_query("SELECT email_address FROM wip ORDER BY email_address ASC");

Reply With Quote
  #9  
Old January 6th, 2003, 01:35 AM
craigyd craigyd is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Sydney, Australia
Posts: 6 craigyd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to craigyd Send a message via Yahoo to craigyd
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:
<?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();

}

$wipemailaddresses*=*"";

while*($row*=*mysql_fetch_array($cust))*{

**$wipemailaddresses*.=*$row["email_address"];

**$wipemailaddresses*.=*", ";

}

?>

Reply With Quote
  #10  
Old January 6th, 2003, 06:48 AM
Attila Attila is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 67 Attila User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Looks good although I use exit like this,

PHP Code:
// exit should look like this:
exit;

//not like you have above:
exit (); 


Atleast that works for me.
__________________
Thanks,
Attila
http://www.glorynaspiration.com
http://www.abitofthings.com

Reply With Quote
  #11  
Old January 6th, 2003, 09:32 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Quote:
Originally posted by craigyd
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:
<?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();

}

$wipemailaddresses*=*"";

while*($row*=*mysql_fetch_array($cust))*{

**$wipemailaddresses*.=*$row["email_address"];

**$wipemailaddresses*.=*", ";

}

?>



PHP 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();

}

$wipemailaddresses "";

while (
$row mysql_fetch_array($cust)) {

  
$wipemailaddresses .= $row["email_address"] . ", ";

}

$wipemailaddresses substr($wipemailaddresses0, -1);

?>

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Importing results from databse into form


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread: