[thelist] PHP function problem

NanHarbisonSmith at aol.com NanHarbisonSmith at aol.com
Fri Mar 1 15:22:01 CST 2002


--
[ Picked text/plain from multipart/alternative ]
Bill,
You are not including all of the statements you need to make, or maybe you
have and are not giving them in your post.  I have started at the very
beginning, with the assignments to the variables for the host, username and
password:

$Host = "localhost";
$User = "username";
$Password = "password";
$DBName = "db";
$TableName = "db_table";
$Link = mysql_connect($Host, $User, $Password);
$Query = "Select USERNAME from $TableName;
$Result = mysql_db_query($DBName, $Query, $Link);

Then you can use this statement to see if you have results:

if (mysql_num_rows($Result1) > 0)
{
do something
}

As you can see, I am using mysql_db_query instead of mysql_query, but I think
mysql_query takes two parameters, the query and the link, unless you already
have a link open.
Nan

---------------original message-------------------
> I'm trying to select a database with mysql_select_db("database") but instead
> use a variable, that was defined with the database name earlier in the code,
> so it looks like :
>
> $db="name";
>
> mysql_select_db($db) ;
> $query="SELECT * form some_table" ;
> $result=mysql_query($query);
>
> but $result is blank and I get error messages saying $result is not a valid
> MySQL value.  If I put in the actual database name i.e ("name") the code
> works fine.  Any suggestions?
>
> Thanks,
> Bill





More information about the thelist mailing list