title: Could not select database
body: <p>Hi guys I'm trying to write some code for a login, I've got it all but whenever I try login it says <strong>Could not select database</strong>. I can't figure it out, I've got hosting with One.com and when I go into the PHP &amp; MySQL settings it says the database name is "c343_co_uk", which is what I've used in the code below:</p>
  
  <p>UPDATE: It's detecting the database but whenever I try and log in with the exact same username and password that's on MySQL it says invalid login</p>
  
  <p>Here is my <strong>Connection.php</strong></p>
  
  <pre><code>&lt;?php
  $username = "c343_co_uk";
  $password = "abc";
  $hostname = "c343.co.uk.mysql"; 
  
  //connection to the database
  $connection = mysql_connect($hostname, $username, $password) 
    or die("Unable to connect to MySQL");
  
  
  $selected = mysql_select_db("c343_co_uk",$dbhandle) 
    or die("Could not select Database");
  
  ?&gt;
  </code></pre>
  
  <p><strong>Loginform.php</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  
  &lt;html&gt;
  
  &lt;a href="index.html" title="back to home"&gt;Home&lt;/a&gt;
  &lt;/font&gt;
      &lt;head&gt;
  
          &lt;style&gt;
              body {
                  font-size: 14px;
              }
  
          &lt;/style&gt;
          &lt;link rel="stylesheet" type="text/css" href="website.css" /&gt;
      &lt;/head&gt;
      &lt;body&gt; 
  
  
      &lt;div id="loginform" style="font-family: 'ClearSans-Thin'; color: Black"&gt;
  
  
          Please enter your login details&lt;br /&gt;&lt;br /&gt;
          Username:&lt;br /&gt;
          &lt;form method="post" action="loginsubmit.php"&gt;
              &lt;input type="text" name="username" /&gt;
              &lt;br /&gt;
              Password:&lt;br /&gt;
              &lt;input type="password" name="password" /&gt;
              &lt;br /&gt;
              &lt;input type="submit" name="submit" value="Submit" /&gt;
          &lt;/form&gt;
          &lt;/center&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>Loginsubmit.php</strong></p>
  
  <pre><code>&lt;?php
  session_start();
  ?&gt;
  &lt;font face="ClearSans-Thin"&gt;
  &lt;font color="lightgray"&gt;
  
  &lt;?php
  
  include 'connection.php';
  include 'loginform.php';
  ?&gt;
  &lt;center&gt;
  &lt;?php
  if (isset($_POST['submit'])) 
      {
      $user = $_POST['username'];
  
      $pass = $_POST['password'];
      //Counts up how many matches there are in the database
      $query = "SELECT COUNT(*) AS cnt FROM users WHERE Username='" . mysqli_real_escape_string($connection, $user) . "' &amp;&amp; Password='" . mysqli_real_escape_string($connection, $pass). "'";
      $result = mysqli_query($connection, $query);
      $row = mysqli_fetch_assoc($result);
  
      $queryadmin = "SELECT COUNT(*) AS cnt FROM admin WHERE Username='" . mysqli_real_escape_string($connection, $user) . "' &amp;&amp; Password='" . mysqli_real_escape_string($connection, $pass). "'";
      $resultadmin = mysqli_query($connection, $queryadmin);
      $rowadmin = mysqli_fetch_assoc($resultadmin);
      //If count is more than 0, log user in.
      if ($row["cnt"] &gt; 0) 
      {
          $_SESSION["userlogged"] =  $user;
          echo "Logged in - Press the home button to return to the homepage";
      } 
      //count for user table is 0, if there are more than 0 matches in the admin database, start admin session
      else if ($rowadmin["cnt"] &gt; 0 )
          {
              $_SESSION["adminlogged"] = $user;
              echo "Logged in - Press the home button to return to the homepage";
          }
      else 
      {
          echo 'Not a valid login';
      }
  }
  ?&gt;
  &lt;/center&gt;
  </code></pre>