jeppers Posted July 4, 2007 Share Posted July 4, 2007 is anything wrong with this code as it works on localhost but when uploaded to server it just says that "Unknown MySQL server host" i am so baffled so if you could help it would be good.... <?php function dbConnect($type) { if ($type == 'query') { $user = nm; $pwd = ps; } else { exit('Unrecognized connection type'); } $conn = mysql_connect(sql1.bravehost.com, nm, ps) or die ('Cannot connect to server'); mysql_select_db('fiction-1261311') or die ('Cannot open database'); return $conn; } ?> Quote Link to comment Share on other sites More sharing options...
jagat21 Posted July 4, 2007 Share Posted July 4, 2007 Hi, in given code there is a function named as dbConnect() in which u have written : $user = nm; $pwd = ps; here what is nm and ps ? if they are any variables then they should be used like $nm and $ps. And if they are any normal string then they must be quoted by single quote or double quote. Another problem with mysql_connect function is that u have written : $conn = mysql_connect(sql1.bravehost.com, nm, ps) or die ('Cannot connect to server'); in this statement there are some syntax errors. it has to be written like this based on ur variables or string. if "nm" and "ps" are normal string then it will be written as $conn = mysql_connect('sql1.bravehost.com','nm', 'ps') or die ('Cannot connect to server'); And if they are varibles then it will be written like this : $conn = mysql_connect('sql1.bravehost.com',$nm, $ps) or die ('Cannot connect to server'); Check it ...... Quote Link to comment Share on other sites More sharing options...
jeppers Posted July 4, 2007 Author Share Posted July 4, 2007 thanks for that but the first problem is that it won't connect to the site at all it stops before it gets to the password and username. the error message is Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host 'sql1bravehostcom' (1) in /misc/13/000/126/295/2/user/web/jeppers90.com/fiction_mysql.inc.php on line 11 Cannot connect to server any ideas Quote Link to comment Share on other sites More sharing options...
jagat21 Posted July 4, 2007 Share Posted July 4, 2007 Hi, can u show the code what u have written ? So that i can come 2 knw where is the problem. Quote Link to comment Share on other sites More sharing options...
jeppers Posted July 4, 2007 Author Share Posted July 4, 2007 <?php function dbConnect($type) { if ($type == 'query') { $user = paul; $pwd = mouse; } else { exit('Unrecognized connection type'); } $conn = mysql_connect(sql1.bravehost.com, $paul, $mouse) or die ('Cannot connect to server'); mysql_select_db('fiction-1261311') or die ('Cannot open database'); return $conn; } ?> Quote Link to comment Share on other sites More sharing options...
jeppers Posted July 4, 2007 Author Share Posted July 4, 2007 after some testing and the use of a mysql testing script i have come to the understanding that it must be my code but i just can't see where so if you have any idea or a slight wim what it could, it would be most helpful this is the code <?php function dbConnect($type) { if ($type == 'query') { $user = paul; $pwd = mouse; } else { exit('Unrecognized connection type'); } $conn = mysql_connect(sql1.bravehost.com, paul, mouse) or die ('Cannot connect to server'); mysql_select_db('fiction-1261311') or die ('Cannot open database'); return $conn; } ?> Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 4, 2007 Share Posted July 4, 2007 Try: <?php function dbConnect($type) { if ($type == 'query') { $user = 'paul';//you need to enclose your strings in quotes $pwd = 'mouse'; } else { exit('Unrecognized connection type'); } $conn = mysql_connect('sql1.bravehost.com', $user, $pwd) or die ('Cannot connect to server<br />'.mysql_error());//its always useful to put in the mysql_error() function in your die statements. That way you can see exactly what mysql had a problem with. mysql_select_db('fiction-1261311') or die ('Cannot open database'); return $conn; } As was said above, if you want to put a piece of text into the function, you'll need to put it in quotes - however, given that you've defined the variables $user and $pwd, im assuming you want to use those. When you define those, you still need to enclose the string in quotes though. Edit :Finally, if those are your real username and password, its unwise to post them. Quote Link to comment Share on other sites More sharing options...
jeppers Posted July 4, 2007 Author Share Posted July 4, 2007 thanks very much as a beginner i greatly thank u one day i hope to be able to help other people.... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.