Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Jan 2012
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    No Database Selected

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

  • #2
    Regular Coder
    Join Date
    Jan 2012
    Posts
    271
    Thanks
    2
    Thanked 65 Times in 65 Posts
    PHP Code:
    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

    PHP Code:
    $db "mydbname"
    mind you $db_host looks weird, that should be localhost or an ip address of the mysql server
    Last edited by jmj001; 01-30-2012 at 06:14 AM.

  • #3
    New Coder
    Join Date
    Jan 2012
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ohh okay. but then

    $db_host = 'TADMS';

    TADMS is my database name.

  • #4
    New Coder
    Join Date
    Jan 2012
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I've also tried changing

    mysql_select_db($db_host,$conn); to

    mysql_select_db("TADMS" ,$conn);

    It still won't work

  • #5
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Are you sure that is your database name? Are you on a shared host?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #6
    New Coder
    Join Date
    Jan 2012
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    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

  • #7
    Regular Coder
    Join Date
    Jan 2012
    Posts
    271
    Thanks
    2
    Thanked 65 Times in 65 Posts
    you need the following info

    PHP Code:
    $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

  • #8
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,639
    Thanks
    0
    Thanked 649 Times in 639 Posts
    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.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #9
    New Coder
    Join Date
    Jan 2012
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey guys! Thanks for all your help. Appreciate it


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •