Page 1 of 1
Query keeps failing
Posted: Tue Aug 07, 2007 12:43 pm
by phpretard
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
Posted: Tue Aug 07, 2007 12:48 pm
by thiscatis
You should add [or die(mysql_error());] to your query, will give you a hint on what's wrong
Here is what it read
Posted: Tue Aug 07, 2007 12:55 pm
by phpretard
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.
Posted: Tue Aug 07, 2007 12:55 pm
by robshanks
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:
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);
Posted: Tue Aug 07, 2007 12:58 pm
by thiscatis
You're not getting the results but just the resource id.
Please provide us the code where you get 'coach'
Which should also be '$coach' for a start
Posted: Tue Aug 07, 2007 1:04 pm
by phpretard
feyd | Please use 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
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]
Posted: Tue Aug 07, 2007 1:31 pm
by phpretard
"SELECT email FROM testemail" <====This sends an email to everyone succesfully.
"SELECT email FROM testemail WHERE league=$league" <====This fails the query
I want to select just the coaches
Posted: Tue Aug 07, 2007 2:10 pm
by phpretard
Thank you for all of your help!!!!
It's working now.
-Anthony
Posted: Tue Aug 07, 2007 6:59 pm
by superdezign
Did no one notice that he was trying to run the result of a query as a query...?
Posted: Tue Aug 07, 2007 7:03 pm
by RobertGonzalez
superdezign wrote:Did no one notice that he was trying to run the result of a query as a query...?
I was just going to ask that

Posted: Tue Aug 07, 2007 7:07 pm
by phpretard
This actually works now (happy me)
Is there any way you folks might look at the topic I posted regarding check boxes?
It's called "Check the box"
Thanky