Hi everyone.

With difficulties trying to insert data from a form field into a database, I have decided to try to just retrieve the data using a SELECT query. It seems I have no trouble connecting to the database (I previously set up an if...then statement that if connected it echoed "you're in"). Below is the code that I'm using to try to show the rows in the database. Can anyone see any problems? The form that calls this .php file as it's action is simply a button.


<?php

// database connection and error(s)
$dbh=mysql_connect ("localhost", "<myusername>", "<mypass>");

if (!$dbh) 
 {
  echo "could not connect to database";
  exit;
 }

// insert code
mysql_select_db('<mydatabase>'); 
$query = "select * from list";
$result = mysql_query($query);

$num_results = mysql_num_rows($result);

echo "number of records: '.$num_results.'";


?>

Any help would be excellent!!

Thanks,

Brian

    Nothing looks out of the ordinary (unless list is an empty table or is not a table).

    Try putting this after $result=
    echo mysql_error();

      Thanks for your reply.

      I tried that and it told me I had no database selected. Hmmmm?

      Brian

        AAHHHHHH....

        I wasn't naming my database correctly. I got it to work.

        Thanks for your time...

        Brian

          Write a Reply...