www.webdeveloper.com
Results 1 to 2 of 2

Thread: No database selected

Hybrid View

  1. #1
    Join Date
    Dec 2011
    Posts
    39

    No database selected

    Sir, I have these codes

    PHP Code:
    <?php

    // Connection variables
    $host     "localhost";
    $username "root";
    $password "";
    $db_name  "phonebook";
    $con      mysql_connect($host$username$password$db_name);

    if (!
    $con) {
        echo (
    '<script type="text/javascript">alert("Error Connecting to database")' mysql_connect_error($con) . '</script>');
    }


    $result   "";
    $username "";
    $password "";

    function 
    clean($str)
    {
        
    $cstr trim($str);
        
    $cstr addslashes($str);
        
    $cstr htmlspecialchars($str);
        return 
    $cstr;
    }

    if (isset(
    $_POST['login'])) {
        
    session_start();
        
        
    $myusername clean($_POST['username']);
        
    $mypassword clean($_POST['password']);
        
        if (empty(
    $myusername) || empty($mypassword)) {
            echo 
    '<script>alert("User name or password must not be empty")</script>';
        } else {
            
    $query "SELECT * FROM admin where username ='" $myusername "' and password='" $mypassword " ' ";
            
    $result mysql_query($query) or die(mysql_error());
        }
        
        if (!
    $result) {
            echo (
    '<script type="text/javascript">alert("username, password query is not working")' mysql_error($con) . '</script>');
        }
        
        
    $count mysql_num_rows($result);
        
        if (
    $count == 1) {
            
    session_register("myusername");
            
    $_SESSION['myusername'] = $myusername;
            
    header("location: welcome.php");
        } else {
            
    $error "Your Login Name or Password is invalid";
        }
    }
    ?>
    Code says:
    No database is selected.

    Database image is follows:
    http://i43.tinypic.com/2j1rdco.jpg

    What i am doing wrong?

  2. #2
    Join Date
    Jun 2013
    Location
    Bangalore
    Posts
    8
    if you are going to use "mysql_connect"

    $con= mysql_connect($host, $username, $password);
    $connect = mysql_select_db($con,$db_name);

    if you are going to use mysqli_connect

    $con= mysqli_connect($host, $username, $password, $db_name);

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles