...

View Full Version : No Database Selected



mln_ndh
01-30-2012, 06:07 AM
Hi,

It always stated that 'No Database Selected'. Really need your help. Thanks :)

This is the coding

<?php
require('include/config.php');
$conn = mysql_connect($db_host, $db_user, $db_pwd);
mysql_select_db($db_host,$conn);
$sql = " SELECT * FROM hod_approval WHERE hod_approval='2' ";
$result = mysql_query($sql) or die (mysql_error());


Here's my config.php

<?php

$db_host = 'TADMS';
$db_user = 'an';
$db_pwd = 'nopassword';

$conn = odbc_connect($db_host, $db_user, $db_pwd);

jmj001
01-30-2012, 06:12 AM
require('include/config.php');
$conn = mysql_connect($db_host, $db_user, $db_pwd);
mysql_select_db($db,$conn); // <-- see the difference here... you may need to change $db to the variable that actually has the database name
$sql = " SELECT * FROM hod_approval WHERE hod_approval='2' ";
$result = mysql_query($sql) or die (mysql_error());

you prob need to add that variable into the config


$db = "mydbname";

mind you $db_host looks weird, that should be localhost or an ip address of the mysql server

mln_ndh
01-30-2012, 06:18 AM
ohh okay. but then

$db_host = 'TADMS';

TADMS is my database name.

mln_ndh
01-30-2012, 06:20 AM
I've also tried changing

mysql_select_db($db_host,$conn); to

mysql_select_db("TADMS" ,$conn);

It still won't work

_Aerospace_Eng_
01-30-2012, 06:24 AM
Are you sure that is your database name? Are you on a shared host?

mln_ndh
01-30-2012, 06:35 AM
Are you sure that is your database name? Are you on a shared host?

Yes I'm very sure that is my database name and yupp it's on shared host

jmj001
01-30-2012, 07:09 AM
you need the following info



$db_host = ""; // your shared host provider will give you this
$db_name = ""; // maybe the name you think.. but on shared hosting it can be different
$db_user = ""; // the db user
$db_pass = ""; // the db user password

// conn needs - db_host, db_user, db_name
$conn = mysql_connect($db_host, $db_user, $db_pass);

// select db needs - db_name + the $conn resource
mysql_select_db($db_name,$conn);

you are missing or have mixed up db_host & db_name

felgall
01-30-2012, 08:18 PM
If the database is on the same server as the script then the host name should be localhost, if on a different server then you would usually refer to it by the IP address unless your hosting provider guarantees that they have a specific domain name you can use that will always point to that server.

On shared hosting the database name and username usually have the account name followed by an underscore on the front.

mln_ndh
01-31-2012, 09:01 AM
Hey guys! Thanks for all your help. Appreciate it :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum