title: php login form using mysql
body: <p>I created an account on 000webhost to create html page that has a login form. But I am facing errors when i try to connect the form to the database.</p>
  
  <p>Here is the html code:</p>
  
  <pre><code>  &lt;html&gt;
  
     &lt;head&gt;
        &lt;title&gt;Login Page&lt;/title&gt;
  
        &lt;style type = "text/css"&gt;
           body {
              font-family:Arial, Helvetica, sans-serif;
              font-size:14px;
           }
  
           label {
              font-weight:bold;
              width:100px;
              font-size:14px;
           }
  
           .box {
              border:#666666 solid 1px;
           }
        &lt;/style&gt;
  
     &lt;/head&gt;
  
     &lt;body bgcolor = "#FFFFFF"&gt;
  
  
  
  
        &lt;div align = "center"&gt;
           &lt;div style = "width:300px; border: solid 1px #333333; " align = "left"&gt;
              &lt;div style = "background-color:#333333; color:#FFFFFF; padding:3px;"&gt;&lt;b&gt;Login&lt;/b&gt;&lt;/div&gt;
  
              &lt;div style = "margin:30px"&gt;
  
                 &lt;form method="POST" action="C1.php"&gt;
                    &lt;label&gt;UserName  :&lt;/label&gt;&lt;input type = "text" name = "username" required = "box"/&gt;&lt;br /&gt;&lt;br /&gt;
                    &lt;label&gt;Password  :&lt;/label&gt;&lt;input type = "password" name = "password" required = "box" /&gt;&lt;br/&gt;&lt;br /&gt;
  
  
                    &lt;input type = "submit" name="submit" value = " Login "/&gt;&lt;br /&gt;
  
                 &lt;/form&gt;
  
                 &lt;div style = "font-size:11px; color:#cc0000; margin-top:10px"&gt;&lt;?php echo $error; ?&gt;&lt;/div&gt;
  
              &lt;/div&gt;
  
           &lt;/div&gt;
  
        &lt;/div&gt;
     &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>here is my php page</p>
  
  <pre><code>       &lt;?php
   session_start();
  $servername = "localhost";
  $username = "******";
  $password = "******";
  
  // Create connection
  $database_name = "id2425621_login";
  $conn = mysqli_connect($servername, $username, $password, $database_name);
  
   if (isset($_POST['submit']))
          {     
  
      $username='king';
      $password='king123';
  
      $query = mysqli_query($conn, "SELECT * FROM mylogin WHERE username='$username' and password='$password'");
       if (mysqli_num_rows($query) != 0)
      {
       echo "sucess";   
        }
        else
        {
      echo "fail";
      }
      }
      ?&gt;
  </code></pre>
  
  <p>mysql has a table named mylogin and has the values:</p>
  
  <pre><code>INSERT INTO `mylogin`(`username`, `password`) VALUES ('king','king123')
  </code></pre>
  
  <p>I couldn't connect to the database, appreciate your help in advance</p>
  
  <p>Thanks</p>