Query keeps failing
Moderator: General Moderators
Query keeps failing
I know I am connecting to the database just fine but my query is failing.
Can someone figure out why based on the code below?
$con=mysql_connect('host',username,password);
@mysql_select_db($database) or die("<b>Unable to specified database</b>");
$query=mysql_query("SELECT email FROM testemail WHERE league= 'coach' ");
$result=mysql_query($query) or die('Error, query failed');
mysql_close($con);
...of course i have a table name "testemail" and a row in that table named "league" and another row named "email".
I am trying to send email to all the people with "coach" in the "league" $row.
[u]P[/u]ulling [u]H[/u]air [u]P[/u]ofusely
Can someone figure out why based on the code below?
$con=mysql_connect('host',username,password);
@mysql_select_db($database) or die("<b>Unable to specified database</b>");
$query=mysql_query("SELECT email FROM testemail WHERE league= 'coach' ");
$result=mysql_query($query) or die('Error, query failed');
mysql_close($con);
...of course i have a table name "testemail" and a row in that table named "league" and another row named "email".
I am trying to send email to all the people with "coach" in the "league" $row.
[u]P[/u]ulling [u]H[/u]air [u]P[/u]ofusely
Here is what it read
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #2' at line 1
But "coach is at the row called "id" #1 not #2
I am not sure if what I just wrote makes sence.
But "coach is at the row called "id" #1 not #2
I am not sure if what I just wrote makes sence.
What is the error you get?
You can try
Are username and pasword variables(1) or do you want to send username and password literally(2)?
If 1 then they need to be entered as $username and $password
Try:
You can try
Are username and pasword variables(1) or do you want to send username and password literally(2)?
If 1 then they need to be entered as $username and $password
Try:
Code: Select all
$con=mysql_connect("host","username","password"); //(1)send strings directly OR
$con=mysql_connect($host,$username,$password); //(2)send variables
if (!$con)
{
die('Could not connect :' . mysql_error());
}
$db=mysql_select_db($database,$con);
if (!$db)
{
die('Could not open databse:' . mysql_error());
}
$query=mysql_query("SELECT email FROM testemail WHERE league= 'coach' ");
$result=mysql_query($query);
if (!$result)
{
die('Error, query failed' . mysql_error());
}
mysql_close($con);feyd | Please use
<---------------------<html form>
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Is this what you're lookin for?Code: Select all
$league=$_POST['league'];
$query=mysql_query("SELECT email FROM testemail WHERE league='$league' ");
$result=mysql_query($query) or die(mysql_error());
mysql_close($con);<---------------------<html form>
Code: Select all
<form action=this.php method=POST>
<select name="league" size="1">
<option>select...</option>
<option value="instructional">Instructional</option>
<option value="rookie">Rookie</option>
<option value="parent">Parent</option>
<option value="coach">Coach</option>
</select>
</form>
</form>feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA