Jump to content


Photo

Connect Script


  • Please log in to reply
3 replies to this topic

#1 famous58

famous58
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 08 March 2006 - 12:12 AM

OK, I'm really close to hurting something.

Can someone take a look at this script and tell me if I have done anything wrong? It will not work, it returns a blank page. If nothing is wrong, is there some kind of php setting that could be causing this? For some reason the php set up on this server seems wacky.

<?php
$Host = "localhost";
$User = "user";
$Password = "password";
$DBName = "database";
$TableName = "users";

$Link = mysql_connect ($Host,$User,$Password);
$Query = "SELECT * from $TableName";
$Result = mysql_db_query ($DBName, $Query, $Link);

while ($Row = mysql_fetch_array ($Result)) {
    print ("hello");
    }
    
?>

T.I.A.
I'm trying, really I am.

#2 php_b34st

php_b34st
  • Members
  • PipPipPip
  • Advanced Member
  • 168 posts

Posted 08 March 2006 - 12:22 AM

Try checking that you are connected, then check if your queryy worked:

<?php
$Host = "localhost";
$User = "user";
$Password = "password";
$DBName = "database";
$TableName = "users";

$Link = mysql_connect ($Host,$User,$Password);
          or die ("Couldn't connect to server.");
$Query = "SELECT * from $TableName";
$Result = mysql_db_query ($DBName, $Query, $Link);

if ($result)
{
    echo 'db connection';
}
else
{
    echo 'problem connecting to db';
}
while ($Row = mysql_fetch_array ($Result)) {
    print ("hello");
    }
    
?>


#3 famous58

famous58
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 08 March 2006 - 12:28 AM

[!--quoteo(post=352691:date=Mar 7 2006, 04:22 PM:name=php_b34st)--][div class=\'quotetop\']QUOTE(php_b34st @ Mar 7 2006, 04:22 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Try checking that you are connected, then check if your queryy worked:

<?php
$Host = "localhost";
$User = "user";
$Password = "password";
$DBName = "database";
$TableName = "users";

$Link = mysql_connect ($Host,$User,$Password);
          or die ("Couldn't connect to server.");
$Query = "SELECT * from $TableName";
$Result = mysql_db_query ($DBName, $Query, $Link);

if ($result)
{
    echo 'db connection';
}
else
{
    echo 'problem connecting to db';
}
while ($Row = mysql_fetch_array ($Result)) {
    print ("hello");
    }
    
?>
[/quote]

Well, I have a problem connecting, but I've triple checked all the variables. How can I see where the connection problem lies?

Edit: Nevermind, I'm retarded. Had the incorrect username
I'm trying, really I am.

#4 TylerL

TylerL
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 08 March 2006 - 12:40 AM

$Link = mysql_connect ($Host,$User,$Password);
          or die (mysql_error());

That should tell you your issues.

I believe theres a query function as well that allows you to set a specific database...I think it's:

bool mysql_select_db ( string database_name [, resource link_identifier] )
[a href=\"http://us2.php.net/manual/en/function.mysql-select-db.php\" target=\"_blank\"]http://us2.php.net/manual/en/function.mysql-select-db.php[/a]

Make sure you are using the proper database name.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users