Retrieving data from MYSQL but not echoing data?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
supaseeds
Forum Newbie
Posts: 13
Joined: Tue Jul 13, 2004 8:09 am

Retrieving data from MYSQL but not echoing data?

Post 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??
User avatar
fresh
Forum Contributor
Posts: 259
Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika

try this:

Post 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??
Last edited by fresh on Sun Aug 01, 2004 5:47 am, edited 1 time in total.
supaseeds
Forum Newbie
Posts: 13
Joined: Tue Jul 13, 2004 8:09 am

Post 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
User avatar
fresh
Forum Contributor
Posts: 259
Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika

Post by fresh »

Look Up ... ;)
supaseeds
Forum Newbie
Posts: 13
Joined: Tue Jul 13, 2004 8:09 am

Post by supaseeds »

Interesting...

I put in your code exactly and it now prints:
Resource id #8

better that nothing i guess but....??
supaseeds
Forum Newbie
Posts: 13
Joined: Tue Jul 13, 2004 8:09 am

Post 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??
supaseeds
Forum Newbie
Posts: 13
Joined: Tue Jul 13, 2004 8:09 am

Post 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&#1111;'date'] . "<br />"; 
echo "Username: " . $row&#1111;'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
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post 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.

:wink:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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"..
User avatar
fresh
Forum Contributor
Posts: 259
Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika

hmmm

Post by fresh »

glad I could help directly and indirectly, at the same time ;)
Post Reply