Jump to content

PHP MYSQL email query problem


phlash2k1

Recommended Posts

Ok, i've been fighting with this script for days now. I need someones help. Code and Tables are posted below.

 

I have a drop down menu that passes the cclpV101RC1divisions.id ($select variable) to an email form where it selects everyone in the division and emails them.

 

I have a similar script that selects everyone on a team (cclpV101RC1players.teamid) and emails them. That works properly, but this is a little more complicated because the cclpV101RC1players table does not have a divisions key to refer to. This is where I need someone's help. Thanks in advance.

 

Here is my code:

<?php
include("dbconnection.php");
$request = $_REQUEST["select"];

if ($_POST["submit"]){ 

//query
$divid = $select;
$sql = "select cclpV101RC1players.id, cclpV101RC1players.email FROM cclpV101RC1players, cclpV101RC1teams WHERE cclpV101RC1teams.division=$divid and cclpV101RC1players.teamid=cclpV101RC1teams.ID";
$query = mysql_query($sql);
if (!$query) {
              // error handler
              echo 'Query failed. SQL: ', $sql, '
Error # ', mysql_errno(), ' Error msg: ', mysql_error();
              exit;
             }
//end of query

while ($row = mysql_fetch_array($query)) {

$email = $row['cclpV101RC1players.email'];
$subject = $_POST["subject"];
$body = $_POST["body"];

mail($email,$subject,$body); 
echo "$email <br><br>"; 
} //end loop
echo "<b>The above email addresses received this message.</b>";

} else{

// display form

?>

<?php

}
// end if


?>

 

 

Here are the tables:

CREATE TABLE `cclpV101RC1divisions` (
  `id` int(4) unsigned zerofill NOT NULL auto_increment,
  `name` varchar(50) NOT NULL default '',
  `list_order` int(3) NOT NULL default '1',
  `disable` int(1) NOT NULL default '1',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;


CREATE TABLE `cclpV101RC1players` (
  `id` int(10) unsigned zerofill NOT NULL auto_increment,
  `lname` varchar(50) NOT NULL default '',
  `fname` varchar(50) NOT NULL default '',
  `birthday` date NOT NULL default '0000-00-00',
  `email` varchar(200) NOT NULL default '',
  `hphone` varchar(20) NOT NULL default '',
  `wphone` varchar(20) NOT NULL default '',
  `address` mediumtext NOT NULL,
  `teamid` int(4) unsigned zerofill NOT NULL default '0000',
  `position` varchar(10) NOT NULL default '',
  `number` int(3) NOT NULL default '0',
  `info` text NOT NULL,
  `photo` varchar(100) NOT NULL default '',
  `registered` int(1) NOT NULL default '0',
  `requested` int(1) NOT NULL default '1',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=56 ;

CREATE TABLE `cclpV101RC1teams` (
  `id` int(4) unsigned zerofill NOT NULL auto_increment,
  `name` varchar(50) NOT NULL default '',
  `contact_name` varchar(70) NOT NULL default '',
  `contact_email` varchar(70) NOT NULL default '',
  `hphone` varchar(20) NOT NULL default '',
  `wphone` varchar(20) NOT NULL default '',
  `address` mediumtext NOT NULL,
  `division` varchar(50) NOT NULL default '',
  `password` varchar(50) NOT NULL default '',
  `info` longtext NOT NULL,
  `photo` varchar(100) NOT NULL default '',
  `photo_cap` mediumtext NOT NULL,
  `disabled` int(1) NOT NULL default '1',
  `dstats` int(1) NOT NULL default '1',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=18 ;

 

Link to comment
https://forums.phpfreaks.com/topic/48786-php-mysql-email-query-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.