<?php
session_start();
$username=$_POST['username'];
$password=$_POST['password'];
if($username&&$password)
{

mysqli_select_db("user",$myconnection) or die("couldn't find db");
$sqlcommand="SELECT * FROM users where username='$username'";
$query= mysqli_query($myconnection,$sqlcommand);

$numrows= mysqli_num_rows($query);
if($numrows!==0)
{
    while($row= mysqli_fetch_assoc($query))
    {
        $dbusername=$row['username'];
        $dbpassword=$row['password'];
    }

    if($username==$dbusername&&md5($password)==$dbpassword)
    {
        echo "you are logged in!";
        $_SESSION['username']=$username;
    }
    else
        echo"your password is incorrect!";

}
else
    die("that user doesn't exits");
}
else
    die("please enter your username and password")
?> 

Recommended Answers

All 2 Replies

Looks incomplete.

  1. The mysqli_select_db() function is used to change the default database for the connection.
  2. $myconnection looks undefined at line 8.

Read the example on how to use mysqli_select_db() at http://www.w3schools.com/php/func_mysqli_select_db.asp

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.