sted999 Posted April 11, 2009 Share Posted April 11, 2009 Hiya all. I am trying to query my database and then display the results of the query (I am wanting the users registration details to be displayed). But no results are being display? Does anyone know why? Thanks very much. <?php $user=($_COOKIE['loginName']); include ('connect.php'); mysql_select_db("a6188092") or die(mysql_error()); $query = "SELECT * FROM Member WHERE loginName='$user'"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { echo "<p>User name : " , ($row['loginName']) , "</p>"; echo "<p>Password : **hidden** </p>"; echo "<p>Secret question : " , ($row['secretQuestion']) , "</p>"; echo "<p>Secret answer : " , ($row['secretAnswer']) , "</p>"; echo "<p>Start town : " , ($row['email']) , "</p>"; echo "<p>Title : " , ($row['title']) , "</p>"; echo "<p>First name : " , ($row['firstName']) , "</p>"; echo "<p>Surname : " , ($row['surname']) , "</p>"; echo "<p>Date of birth : " , ($row['DOB']) , "</p>"; echo "<p>Gender : " , ($row['gender']) , "</p>"; echo "<br />"; } mysql_free_result($result); mysql_close(); ?> Quote Link to comment Share on other sites More sharing options...
jackpf Posted April 11, 2009 Share Posted April 11, 2009 Put or die(mysql_error()); after your query. Should be more useful. Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted April 11, 2009 Share Posted April 11, 2009 what are the commas for is your returned results? have you echo'd $user? is it what you think it is? is your db connection working? are these real fields : $query = "SELECT * FROM [b]Member[/b] WHERE [b]loginName[/b]='$user'"; other than that, some error messages would be nice. Quote Link to comment Share on other sites More sharing options...
AdRock Posted April 11, 2009 Share Posted April 11, 2009 echo "<p>User name : {$row['loginName'])}</p>"; echo "<p>Password : **hidden** </p>"; echo "<p>Secret question : {($row['secretQuestion'])}</p>"; echo "<p>Secret answer : {($row['secretAnswer'])}</p>"; echo "<p>Start town : {($row['email'])}</p>"; echo "<p>Title : {($row['title'])}</p>"; echo "<p>First name : {($row['firstName'])}</p>"; echo "<p>Surname : {($row['surname'])}</p>"; echo "<p>Date of birth : {($row['DOB'])}</p>"; echo "<p>Gender : {($row['gender'])}</p>"; Quote Link to comment Share on other sites More sharing options...
sted999 Posted April 11, 2009 Author Share Posted April 11, 2009 This one is puzzling me. When i mannually chose the value for the query e.g. - $query = "SELECT * FROM Member WHERE loginName='stephen' "; I get the results i need. But when i change it to the variable, no such luck ???. This would suggest that the variable is wrong, but i am getting the correct answer when i echo it?!? Is the query wrong? The table name and field names are correct. About the commas being used, i found an example and have used it elsewhere in my website and it works, thats why i have stuck to it. Would you reccomend against them? Im new to php so not sure about the best way to do things yet. Code so far - <?php $user=($_COOKIE['loginName']); echo "$user"; include ('connect.php'); mysql_select_db("a6188092") or die(mysql_error()); $query = "SELECT * FROM Member WHERE loginName='$user' "; echo mysql_error(); $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { echo "<p>User name : " , ($row['loginName']) , "</p>"; echo "<p>Password : **hidden** </p>"; echo "<p>Secret question : " , ($row['secretQuestion']) , "</p>"; echo "<p>Secret answer : " , ($row['secretAnswer']) , "</p>"; echo "<p>Email address : " , ($row['email']) , "</p>"; echo "<p>Title : " , ($row['title']) , "</p>"; echo "<p>First name : " , ($row['firstName']) , "</p>"; echo "<p>Surname : " , ($row['surname']) , "</p>"; echo "<p>Date of birth : " , ($row['DOB']) , "</p>"; echo "<p>Gender : " , ($row['gender']) , "</p>"; } mysql_free_result($result); mysql_close(); ?> Quote Link to comment Share on other sites More sharing options...
unrelenting Posted April 11, 2009 Share Posted April 11, 2009 This one is puzzling me. When i mannually chose the value for the query e.g. - $query = "SELECT * FROM Member WHERE loginName='stephen' "; I get the results i need. But when i change it to the variable, no such luck ???. This would suggest that the variable is wrong, but i am getting the correct answer when i echo it?!? Is the query wrong? The table name and field names are correct. About the commas being used, i found an example and have used it elsewhere in my website and it works, thats why i have stuck to it. Would you reccomend against them? Im new to php so not sure about the best way to do things yet. Code so far - <?php $user=($_COOKIE['loginName']); echo "$user"; include ('connect.php'); mysql_select_db("a6188092") or die(mysql_error()); $query = "SELECT * FROM Member WHERE loginName='$user' "; echo mysql_error(); $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { echo "<p>User name : " , ($row['loginName']) , "</p>"; echo "<p>Password : **hidden** </p>"; echo "<p>Secret question : " , ($row['secretQuestion']) , "</p>"; echo "<p>Secret answer : " , ($row['secretAnswer']) , "</p>"; echo "<p>Email address : " , ($row['email']) , "</p>"; echo "<p>Title : " , ($row['title']) , "</p>"; echo "<p>First name : " , ($row['firstName']) , "</p>"; echo "<p>Surname : " , ($row['surname']) , "</p>"; echo "<p>Date of birth : " , ($row['DOB']) , "</p>"; echo "<p>Gender : " , ($row['gender']) , "</p>"; } mysql_free_result($result); mysql_close(); ?> Try: $query = "SELECT * FROM Member WHERE loginName='".$user."'"; Quote Link to comment Share on other sites More sharing options...
sted999 Posted April 11, 2009 Author Share Posted April 11, 2009 Still no results Quote Link to comment Share on other sites More sharing options...
unrelenting Posted April 11, 2009 Share Posted April 11, 2009 Still no results Are you absolutely sure that there is a row in the Member table with the loginName = to $user? Quote Link to comment Share on other sites More sharing options...
unrelenting Posted April 11, 2009 Share Posted April 11, 2009 Try trim($user); Quote Link to comment Share on other sites More sharing options...
sted999 Posted April 11, 2009 Author Share Posted April 11, 2009 Yeh, ive only got two records so thats why its puzzling me so much. I have gone back a few steps to try and get it working, ive changed the variable name to what i need and then queried using the variable, but still i get no results. surely once i get this query working, all I will have to change is the variable declarartion to make it work. Sorry if im being really thick on this, my brain is frazzled and ive tried every possible combination i can think of. Thanks <?php $user="stephen"; echo "$user"; include ('connect.php'); mysql_select_db("a6188092") or die(mysql_error()); $query = "SELECT * FROM Member WHERE loginName='".$user."'"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { echo "<p>User name : " , ($row['loginName']) , "</p>"; echo "<p>Password : **hidden** </p>"; echo "<p>Secret question : " , ($row['secretQuestion']) , "</p>"; echo "<p>Secret answer : " , ($row['secretAnswer']) , "</p>"; echo "<p>Start town : " , ($row['email']) , "</p>"; echo "<p>Title : " , ($row['title']) , "</p>"; echo "<p>First name : " , ($row['firstName']) , "</p>"; echo "<p>Surname : " , ($row['surname']) , "</p>"; echo "<p>Date of birth : " , ($row['DOB']) , "</p>"; echo "<p>Gender : " , ($row['gender']) , "</p>"; echo "<br />"; } mysql_free_result($result); mysql_close(); ?> Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted April 11, 2009 Share Posted April 11, 2009 <?php #error reporting; error_reporting(E_ALL); include ('connect.php'); mysql_select_db("a6188092") or die(mysql_error()); if (isset ($_COOKIE['loginName'])) { $query = mysql_query(sprintf("SELECT * FROM Member WHERE loginName='%s'", mysql_real_escape_string(trim($_COOKIE['loginName'])))) or die ('SQL Error: ' . mysql_error()); if (mysql_num_rows($query) > 0) { while ($row = mysql_fetch_array($query)) { echo '<p>User name : '.$row['loginName']).'</p>'; //continue down changing to look like this; echo "<p>Password : **hidden** </p>"; echo "<p>Secret question : " , ($row['secretQuestion']) , "</p>"; echo "<p>Secret answer : " , ($row['secretAnswer']) , "</p>"; echo "<p>Start town : " , ($row['email']) , "</p>"; echo "<p>Title : " , ($row['title']) , "</p>"; echo "<p>First name : " , ($row['firstName']) , "</p>"; echo "<p>Surname : " , ($row['surname']) , "</p>"; echo "<p>Date of birth : " , ($row['DOB']) , "</p>"; echo "<p>Gender : " , ($row['gender']) , "</p>"; } } else { echo 'no results found.'; } } else { echo '$_COOKIE["loginName"] isn't even set.'; } ?> Quote Link to comment Share on other sites More sharing options...
jackpf Posted April 11, 2009 Share Posted April 11, 2009 Or you could try doing what i stated this morning and put or die(mysql_error()); after your query... Quote Link to comment Share on other sites More sharing options...
sted999 Posted April 12, 2009 Author Share Posted April 12, 2009 Thanks for your help guys. Its sorted now. Cheers. Quote Link to comment 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.