Page 1 of 1
MySQL Error
Posted: Thu Mar 06, 2008 7:56 pm
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'];
}
?>
Re: MySQL Error
Posted: Thu Mar 06, 2008 8:55 pm
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();
}
Re: MySQL Error
Posted: Thu Mar 06, 2008 10:15 pm
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?
Re: MySQL Error
Posted: Fri Mar 07, 2008 6:00 pm
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();
}
Re: MySQL Error
Posted: Sat Mar 08, 2008 12:27 pm
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();
}
?>
Re: MySQL Error
Posted: Sat Mar 08, 2008 6:38 pm
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();
}
Re: MySQL Error
Posted: Mon Mar 10, 2008 12:18 pm
by JayBird
Please post in the correct forum.
Moved to Databases