我的代码不在服务器上运行。 它显示没有选择数据库

My connection file is conn.php, adminname and password are the table field name and form text box name. when this code run on server FTP it shows No database selected. But i include connection file and update database on FTP server. This code is run on local wamp server.

**my login coding is:**
// this is my login page.
<?php
session_start();
// start here session
include('conn.php');
//  here include connection file
if(isset($_POST['login']))
{
    $sql="select * from admin where adminname='".$_POST['adminname']."'and password='".$_POST['password']."'";
    // this is my sql query which select adminname and password in table
    $result=mysql_query($sql) or die(mysql_error());
    if($result)
    {
        $row=mysql_fetch_array($result);
        if(mysql_num_rows($result)>0)
        {
            $_SESSION['admin']=$row['adminname'];
            header("location:home.php");
        }   
        else
        {
            header("location:index.php");
        }
    }
}
?>

Make sure about few things:

  1. First check if you have created a database or not?
  2. Make sure you entered the correct db_hostame, db_username, db_password, dbname

tricky way to make a database connection that works in your localhost and real server is:

$host = $_SERVER['HOST_NAME'];

if( $host == "localhost" ){
    // localhost settings
}
else{
    // Server Settings
}

it's just a simple trick.

add one line in conn file after getting connection from database

    <?php
mysql_select_db ( string $database_name);
   ?>