PDA

View Full Version : Problems connecting with DB via PHP


jpharper
2-21-04, 10:05 PM
Just beginning to write code in PHP and cannot seem to connect to my DB via a PHP program.

The code is

mysql_connect("mysql05.powweb.com", "mysqlID", "mysqlpassword");

$Result = mysql_query("select * from dgfly.TruckInv where UserID = '$UserID'");

print "Result $Result<br>";
if ($Result) {
if (mysql_num_rows($Result) > 0) {
print "Access Granted";
$Found = true;
}
}

The "mysqlID" is the ID which works just fine with the phpmyadmin server interface and the "mysqlpassword" which I use there.

Thanks for any pointers

HalfaBee
2-21-04, 10:48 PM
You need to add another line.

mysql_select_db( 'dbname' );

after the mysql_connect()

jpharper
2-22-04, 05:59 PM
Despite adding this line and trying what seems like 100 other permutations of the php/sql commands, I am still getting nada...

HalfaBee
2-22-04, 06:04 PM
You have to use mysql_fetch_array() to get the results.

while( $row=mysql_fetch_array( $Result ) ) {
print_r( $row );
}