...

View Full Version : SOLVED Probally a simple solution: query table doesn't work



cowkiller6
07-02-2005, 08:41 PM
I am trying to simply query a table and assign the value to a variable.

I have a database named test, with a table called bank and 2 column, id and amount

There is one row with id=1 and amount=50

I am using the following php code to try and get the amount from the row with the id=1 and echo it. I have never had problems doing this before, but this time I get:


Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/techgear/public_html/getCityState.php on line 21
invalid

Here is my code:


<?php
/**
* Connects to the database.
* Return false if connection failed.
* Be sure to change the $database_name. $database_username , and
* $database_password values to reflect your database settings.
*/
function db_connect() {
$database_name ='test'; // Set this to your Database Name
$database_username ='*********'; // Set this to your MySQL username
$database_password ='*********'; // Set this to your MySQL password
$result = mysql_pconnect('localhost',$database_username, $database_password);
if (!$result) return false;
if (!mysql_select_db($database_name)) return false;
return $result;
}
$conn = db_connect(); // Connect to database
if ($conn) {
$query = "select * from bank where id = '1'";
$result = mysql_query($query,$conn);
$count = mysql_num_rows($result);
if ($count > 0) {
$city = mysql_result($result,0,'amount');
}
}
if (isset($city)) {
$return_value = $city;
}
else {
$return_value = "invalid"; // Include Zip for debugging purposes
}
echo $return_value; // This will become the response value for the XMLHttpRequest object
?>

cowkiller6
07-02-2005, 09:20 PM
Wow! I spent one hour trying to find the problem. Well, the problem was in my database the table is Bank not bank.

:o



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum