Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2005
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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 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
    ?>
    Last edited by cowkiller6; 07-02-2005 at 09:19 PM.

  • #2
    New Coder
    Join Date
    Jun 2005
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Wow! I spent one hour trying to find the problem. Well, the problem was in my database the table is Bank not bank.



  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •