Page 1 of 1
Retrieving data from MYSQL but not echoing data?
Posted: Sun Aug 01, 2004 4:58 am
by supaseeds
Code: Select all
<?php
include ( "defaults.php" );
include ( "connect.php" );
mysql_query("SELECT useremail FROM email WHERE emailname=1") or die (mysql_error());
$result=mysql_query($query);
echo $result;
mysql_close();
exit();
?>
Hi, I've got a valid entry in the database where emailname = 1 and an email address has been set in field useremail but the page prints nothing, any ideas??
try this:
Posted: Sun Aug 01, 2004 5:28 am
by fresh
Code: Select all
<?php
require ( "defaults.php" );
require ( "connect.php" );
$query = "SELECT useremail FROM email WHERE emailname = '1'";
$result = mysql_query($query);
echo "".$result."";
?>
hows that now??
Posted: Sun Aug 01, 2004 5:38 am
by supaseeds
Thanks, but it still displays absolutely nothing... literally all I won't to do is display one field from the MYSQL DB! Is there anyway I can re-write this code altogether? I can't see any reason why it shouldn't work though.... Could it be anything to do with the settings for the fields in the database?
Table Properties
Properties of the table 'email' are shown below
Field Type Null Key Default Extra Action
emailname int(11) MUL auto_increment Change Drop Primary Index Unique
useremail text YES Change Drop Primary Index Unique
Keys Key name Unique Field Action
emailname NO emailname Drop
Posted: Sun Aug 01, 2004 5:42 am
by fresh
Look Up ...

Posted: Sun Aug 01, 2004 5:51 am
by supaseeds
Interesting...
I put in your code exactly and it now prints:
Resource id #8
better that nothing i guess but....??
Posted: Sun Aug 01, 2004 5:52 am
by supaseeds
oh yea, it should be printing someones email address by the way..
The page now just produces the same ID error everytime, the problem must be on
$query = "SELECT useremail FROM email WHERE emailname = '1'";
but it seems incredibly basic??
Posted: Sun Aug 01, 2004 6:25 am
by supaseeds
LOL - Fresh, I ran a search on this site for Resource ID and without knowing went into your database thread, copied the code they gave you:
Code: Select all
$sql = "SELECT * FROM users ORDER BY reg_date LIMIT 1";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
echo "Date: " . $rowї'date'] . "<br />";
echo "Username: " . $rowї'username'];
and bling, works fine. Still got no idea why my code doesn't work, seems stupid to me but hey... thanks for the help
Posted: Sun Aug 01, 2004 10:17 am
by tim
perhaps if you used error_reporting and intergrated some:
or die(mysql_error()); to your MySQL commands, you could troubleshoot what the problem is.

Posted: Sun Aug 01, 2004 10:18 am
by feyd
your code didn't work because you run a mysql query, do not store the returned value, then run another query with a nonexistant variable, storing that return. That return, if it had anything would also print "Resource Id #X"..
hmmm
Posted: Sun Aug 01, 2004 10:54 am
by fresh
glad I could help directly and indirectly, at the same time
