Jump to content

[SOLVED] can you help


jeppers

Recommended Posts

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;
  }
?>

Link to comment
Share on other sites

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 ......  ;)

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

<?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;

  }

?>

Link to comment
Share on other sites

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;
  }
?>

Link to comment
Share on other sites

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.

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.