please help me
when i run my code
by using Mysql_num_rows()
Warning: Supplied argument is not a valid MySQL result resource in c:\inetpub\wwwroot\php\connect to database.php on line 13

this is my code

<?php
/* declar some relevant variables */
$Host = "localhost"; //location of mySQL on server
$Table = "books"; //name of the table within the database

     mysql_connect ($Host,$Table) or
     die ("unable to connect to database");
     //mysql_select_db("$Name") or
     //die ("unable to select DB");
     $sqlquery = "SELECT * FROM $Table";
     $result = Mysql_query($sqlquery);
     $number = Mysql_num_rows($result); 


?>

what shall i do

:confused:

<?
$host = "localhost";
$user = "me"
$pass = "super-secret";
$database = "db";
$table = "books";

//you need to put them in this order, the table name does not go here!
$db = mysql_connect ($host, $user, $pass) or die ('I cannot connect to the database because: ' . mysql_error());

//you must select a db, as all tables are in a database
mysql_select_db($db);

$sql_query = "SELECT * FROM $Table";
$result = mysql_query($sql_query);
if ($result == 0)
{
     echo "I had a problem running the query!";
     $number = 0;
}
else
{
     echo "my sql query ran sucsessfully";
     $number = mysql_num_rows($result);
}
mysql_close();
?>

you'll notice i put the mysql error number in case there was an error opening the database, I also checked to make sure usign the if statement, add all this extra junk to see where you are going wrong, and then once you figure it out then just clean it up a bit

As paradox has shown with his example, you left out the database, varible so mysql won't know what database it needs to get its data from.

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.