Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
IT-Guy
Forum Newbie
Posts: 7 Joined: Sat Feb 16, 2008 8:44 pm
Post
by IT-Guy » Thu Mar 06, 2008 7:56 pm
Im trying to list all the email addresses from my database onto a page, but I keep getting this error, problem is I dont see any error on Line 6 - Here is the error and script
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in D:\hosting\member\aiim\affiliates\email.php on line 6
Code: Select all
<?php
$con = mysql_connect("****","****","****") or die('Could not connect: ' . mysql_error());
mysql_select_db("subscribe", $con);
$result = mysql_query("SELECT * FROM subscribe");
while($row = mysql_fetch_assoc($result)){
$row['email'];
}
?>
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Thu Mar 06, 2008 8:55 pm
Always do error checking. MySQL really wants to tell you what the problem is.
Code: Select all
$con = mysql_connect("****","****","****") or die('Could not connect: ' . mysql_error());
if (mysql_errno()) {
echo 'Connect error: ' . mysql_error();
}
mysql_select_db("subscribe", $con);
$result = mysql_query("SELECT * FROM subscribe");
if (! mysql_errno()) {
while($row = mysql_fetch_assoc($result)){
$row['email'];
}
} else {
echo 'Query error: ' . mysql_error();
}
(#10850)
IT-Guy
Forum Newbie
Posts: 7 Joined: Sat Feb 16, 2008 8:44 pm
Post
by IT-Guy » Thu Mar 06, 2008 10:15 pm
Ok, I tried the code below, now there are no errors, except its now just displaying a blank white page...
Why is that, does anyone know?
flying_circus
Forum Regular
Posts: 732 Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR
Post
by flying_circus » Fri Mar 07, 2008 6:00 pm
IT-Guy wrote: Ok, I tried the code below, now there are no errors, except its now just displaying a blank white page...
Why is that, does anyone know?
Well IT-Guy, the reason you're staring at a blank white page is because you haven't told PHP to output anything. I put an echo statement in the code, but not knowing more about the database, I cant garuantee this will output anything either. I also kind of figured you'd want to do something more substantial than just output a concatenated string of email addresses.
Code: Select all
$con = mysql_connect("****","****","****") or die('Could not connect: ' . mysql_error());
if (mysql_errno()) {
echo 'Connect error: ' . mysql_error();
}
mysql_select_db("subscribe", $con);
$result = mysql_query("SELECT * FROM subscribe");
if (! mysql_errno()) {
while($row = mysql_fetch_assoc($result)){
echo $row['email'];
}
} else {
echo 'Query error: ' . mysql_error();
}
IT-Guy
Forum Newbie
Posts: 7 Joined: Sat Feb 16, 2008 8:44 pm
Post
by IT-Guy » Sat Mar 08, 2008 12:27 pm
Finally! It worked! But, I want to separate each email address with a semi colon, any advice on how I do that?
Code: Select all
<?php
$con = mysql_connect("**","***","****") or die('Could not connect: ' . mysql_error());
if (mysql_errno()) {
echo 'Connect error: ' . mysql_error();
}
mysql_select_db("login", $con);
$result = mysql_query("SELECT * FROM subscribe");
if (! mysql_errno()) {
while($row = mysql_fetch_assoc($result)){
echo $row['email'];
}
} else {
echo 'Query error: ' . mysql_error();
}
?>
flying_circus
Forum Regular
Posts: 732 Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR
Post
by flying_circus » Sat Mar 08, 2008 6:38 pm
Yup sure, try this:
Code: Select all
$con = mysql_connect("****","****","****") or die('Could not connect: ' . mysql_error());
if (mysql_errno()) {
echo 'Connect error: ' . mysql_error();
}
mysql_select_db("subscribe", $con);
$result = mysql_query("SELECT * FROM subscribe");
if (! mysql_errno()) {
while($row = mysql_fetch_assoc($result)){
echo $row['email'] . ';';
}
} else {
echo 'Query error: ' . mysql_error();
}
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Mon Mar 10, 2008 12:18 pm
Please post in the correct forum.
Moved to Databases