Im writing some code to send out emails for work. And i've been stuck on with this error for a while nw. Any help will be greatly appreciated.

Error message: Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\wamp\www\PHP\mailMany.php on line 21

Heres my code:

<?php
// Check, if submitted.
//if($submit)
if(isset($_POST['submit'])){

// Get variables from POST method form.
$subject=$_POST['subject'];
$note=$_POST['note'];

$sender="joelyonswork@gmail.com"; // Your Email here.

echo "Email has been sent to:";

// Connect database
mysql_connect("localhost","root","");
mysql_select_db("commercialenterprise");

$rs=mysql_query("select CommercialEnterprise_Email from commercialenterprise WHERE 'town' = 'Killkee'");

// Do while loop to send email.

The Line below is where error is.

while($row=mysql_fetch_assoc($rs)){
$to=$row['email'];
$mail_from="From:$email n";
$mail_from .="Content-Type: text/html; charset=utf-8 n";

mail($to,$subject,$note,$mail_from);

// Show sent emails.
echo "$row[email]<br>";
}
}
else{

// Do following codes if not found "Submit" value.(Not submitted)
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<title>Email Form</title>
<body>
<form action="<? echo $PHP_SELF; ?>" method="post" name="form" id="form">
<table>
<tr>
<td align="right">Subject : </td>
<td><input name="email" type="text" id="email" /></td>
</tr>
<tr>
<td align="right" valign="top">Note : </td>
<td><textarea name="comment" cols="60" rows="5" id="comment"></textarea></td>
</tr>
</table>
<input type="submit" name="Submit" value="Send Email" />
</form>
</body>
</html>
<?php } ?>

Thanks in advance :)

Replace the quotes that surrounds the field name 'town' with back ticks, so this:

$rs=mysql_query("select CommercialEnterprise_Email from commercialenterprise WHERE 'town' = 'Killkee'");

Becomes:

$rs=mysql_query("select CommercialEnterprise_Email from commercialenterprise WHERE `town` = 'Killkee'");

If you still get errors add mysql_error(): http://php.net/manual/en/function.mysql-error.php

Am assuming that your line 21 is the select statement, ryt?? If so, then your query should be;

$rs=mysql_query("select CommercialEnterprise_Email from commercialenterprise WHERE town = 'Killkee'");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.