famous58 Posted March 8, 2006 Share Posted March 8, 2006 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 https://forums.phpfreaks.com/topic/4390-connect-script/ Share on other sites More sharing options...
php_b34st Posted March 8, 2006 Share Posted March 8, 2006 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 https://forums.phpfreaks.com/topic/4390-connect-script/#findComment-15235 Share on other sites More sharing options...
famous58 Posted March 8, 2006 Author Share Posted March 8, 2006 [!--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 https://forums.phpfreaks.com/topic/4390-connect-script/#findComment-15237 Share on other sites More sharing options...
TylerL Posted March 8, 2006 Share Posted March 8, 2006 [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 https://forums.phpfreaks.com/topic/4390-connect-script/#findComment-15239 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.