monkeybidz Posted February 28, 2008 Share Posted February 28, 2008 I need to get the email for a user using a query. Here is what I have so far: <?php $query = "SELECT email FROM PHPAUCTIONXL_users WHERE nick='$user_nick'"; $email = mysql_query("email");//<-- <-- This is my problem. ?> I also tried this: <?php $query = "SELECT email FROM PHPAUCTIONXL_users WHERE nick='$user_nick'"; $result =mysql_query($query); $email = mysql_query($result,0,"email"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/93467-need-help-getting-an-email-in-query/ Share on other sites More sharing options...
Psycho Posted February 28, 2008 Share Posted February 28, 2008 <?php $query = "SELECT email FROM PHPAUCTIONXL_users WHERE nick='$user_nick'"; $result =mysql_query($query) or die (mysql_error()); $record = mysql_fetch_assoc($result); $email = $record['email']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/93467-need-help-getting-an-email-in-query/#findComment-478862 Share on other sites More sharing options...
monkeybidz Posted February 28, 2008 Author Share Posted February 28, 2008 I get nothing. I have $email set to echo in page to see if there is a result, but nothing. Quote Link to comment https://forums.phpfreaks.com/topic/93467-need-help-getting-an-email-in-query/#findComment-478868 Share on other sites More sharing options...
trq Posted February 28, 2008 Share Posted February 28, 2008 Where is $user_nick defined? Quote Link to comment https://forums.phpfreaks.com/topic/93467-need-help-getting-an-email-in-query/#findComment-478879 Share on other sites More sharing options...
monkeybidz Posted February 28, 2008 Author Share Posted February 28, 2008 It is defined all over the page in other code not shown here and echoes OK after this query. Quote Link to comment https://forums.phpfreaks.com/topic/93467-need-help-getting-an-email-in-query/#findComment-478881 Share on other sites More sharing options...
trq Posted February 28, 2008 Share Posted February 28, 2008 It is defioned all over the page? Sounds interesting. Any reason why its defined moire than once? Anyway, lets try some decent debuging. <?php $query = "SELECT email FROM PHPAUCTIONXL_users WHERE nick='$user_nick'"; if ($result =mysql_query($query)) { if (mysql_num_rows($result)) { $record = mysql_fetch_assoc($result); $email = $record['email']; } else { echo "No record found matching $user_nick"; } } else { echo "Query failed<br />$sql<br />" . mysql_error(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/93467-need-help-getting-an-email-in-query/#findComment-478893 Share on other sites More sharing options...
monkeybidz Posted February 28, 2008 Author Share Posted February 28, 2008 <?php $query = "SELECT email FROM PHPAUCTIONXL_users WHERE nick='$user_nick'"; $result =mysql_query($query) or die (mysql_error()); $record = mysql_fetch_assoc($result); $email = $record['email']; ?> This code worked, and so did one of mine. The problem was that I set this query to only work if a form was submitted. I had this above the query. <?php if($_POST['Submit']) { $query = "SELECT email FROM PHPAUCTIONXL_users WHERE nick='$user_nick'"; $result =mysql_query($query) or die (mysql_error()); $record = mysql_fetch_assoc($result); $email = $record['email']; ?> It slipped my mind. Thank guys. Quote Link to comment https://forums.phpfreaks.com/topic/93467-need-help-getting-an-email-in-query/#findComment-478897 Share on other sites More sharing options...
trq Posted February 28, 2008 Share Posted February 28, 2008 Still, that is poor coding practive. My example is much better. You should always check your queries succeed and return a result before trying to use them. Quote Link to comment https://forums.phpfreaks.com/topic/93467-need-help-getting-an-email-in-query/#findComment-478900 Share on other sites More sharing options...
monkeybidz Posted February 28, 2008 Author Share Posted February 28, 2008 I will give it a shot. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/93467-need-help-getting-an-email-in-query/#findComment-478902 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.