Im setting up a php log in for my website. I have the php code in a seperate php file and I am calling the form action for that php file. All the names from the html do match the ones in the php. When I click Login regardless whether it has any input or not, it redirects me to an empty page with a address "mywebsite.com/login.php?username=&password=" . When it should echo that the username or password is invalid.
><?php
session_start();
//Creates connection
$con = mysqli_connect("my info and stuff") or die("Error " . mysqli_error($con));
$db = mysqli_select_db($con,"users");
if(isset($_POST["Login"])){
$username = mysqli_real_escape_string($connect, $_POST["username"]);
$password = mysqli_real_escape_string($connect, CRYPT_MD5($_POST["password"]));
$query = mysqli_query("SELECT id, username FROM users WHERE username = '$username' AND password = '$password' ");
$result = mysqli_query($query);
$row = mysqli_num_rows($result);
if($row == 1){
session_register("username");
session_register("password");
header("location: profile.php");
}
else {
echo ("Wrong Username or Password");
}
}
?>
If theres a more efficient ways of making this, would appreciate the suggestions. Still very new to php.