Jump to content

[SOLVED] Not echoing query results


sted999

Recommended Posts

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();

	?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>";

Link to comment
Share on other sites

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();

	?>

Link to comment
Share on other sites

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."'";

 

Link to comment
Share on other sites

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();

	?>

Link to comment
Share on other sites

<?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.';
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.