MySQL Error

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
IT-Guy
Forum Newbie
Posts: 7
Joined: Sat Feb 16, 2008 8:44 pm

MySQL Error

Post by IT-Guy »

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'];
}
?>
 
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: MySQL Error

Post by Christopher »

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

Re: MySQL Error

Post by IT-Guy »

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?
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: MySQL Error

Post by flying_circus »

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

Re: MySQL Error

Post by IT-Guy »

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();
}
?>
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: MySQL Error

Post by flying_circus »

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();
}
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Re: MySQL Error

Post by JayBird »

Please post in the correct forum.

Moved to Databases
Post Reply