Good afternoon,

I'm hoping you guys can help me out with a simple problem. I am working on my first AJAX powered app, and I'm having a problem with the PHP portion. I am passing a value "q" from my app, that should return a Country name. Instead, I get a Resource id #3. My echo commands for $q and $sql are correct, and the generated query returns the proper result in MySQL query.

What am I missing?

$q = $_GET["q"];

$host="localhost";
$user="root";
$password="******";

$connection=mysql_connect($host,$user,$password);
$db=mysql_select_db("******",$connection)
or die (mysql_error());

$sql="SELECT Country FROM country WHERE CountryID = '" . $q . "'";
$result=mysql_query($sql)
	or die(mysql_error());

echo $result . "<br />";
echo $q . "<br />";
echo $sql;

Sample result:
Resource id #3
0000000003
SELECT Country FROM country WHERE CountryID = '0000000003'

Thank you!!!

Eric

mysql_query returns an object, not a string. you have to use mysql_fetch_array or mysql_fetch_assoc to turn the resulting resource set into an array.
http://us.php.net/mysql_fetch_assoc

Perfect. That did it!

I changed:

echo $result;

to:

$Countryrow = mysql_fetch_assoc($result);
echo $Countryrow["Country"];

Thanks for the help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.