Jump to content

Connect Script


famous58

Recommended Posts

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.

[code]<?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");
    }
    
?>[/code]

T.I.A.
Link to comment
Share on other sites

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

[code]<?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");
    }
    
?> [/code]
Link to comment
Share on other sites

[!--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) [snapback]352691[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Try checking that you are connected, then check if your queryy worked:

[code]<?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");
    }
    
?> [/code]
[/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
Link to comment
Share on other sites

[code]$Link = mysql_connect ($Host,$User,$Password);
          or die (mysql_error());[/code]

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.