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
https://forums.phpfreaks.com/topic/153629-solved-not-echoing-query-results/
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.

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

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

	?>

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

 

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

	?>

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.