I'm completely new to programming in PHP so I looked up a tutorial on youtube, came across the phpacademy tutorial for making a login page script. I followed everything as mentioned in the video but for some reason, I can login without a username or password entered and on top of that it's not displaying any of the messages I added in the code. I'm using Xampp for my Apache server and MySQL, configured everything I should of (as far as I know) but it still refuses to work.
Here's the html for the login page, just a basic form.
<html>
<form action='login.php' method='POST'>
Username: <input type='text' name='username'><br>
Password: <input type='password' name='password'><br>
<input type='submit' value='Log in'>
</html>
And then we have the PHP code which isn't working AT ALL. It's like it's not reading it at all for some reason and I can't figure out why.
<?php
$connect = mysql_connect("localhost", "root", "") or die("Couldn't connect!");
mysql_select_db("phplogin") or die("Couldn't find DB");
$connection =@ mysql_connect($db['server'], $db['user'], $db['password']) or die (include_once("offline.php"));
$db =@ mysql_select_db($db['database']) or die (include_once("offline.php"));
if($_POST['username'] && $_POST['password']){
$username = trim($_POST['username']);
$password = trim($_POST['password']);
$query = mysql_query("SELECT * FROM `users` WHERE `username` = '$username' AND `password` = '$password'");
$numrows = mysql_num_rows($query);
if ($numrows > 0){
echo "Username & Password correct (Logged in)";
} else {
echo "That user doesn't exist";
}
} else {
echo "Please enter a username and password!";
}
?>
One thing I should mention is that, if I try to login on firefox it shows part of my php code as text, if I open it on Opera it displays the whole php code as text. Any ideas? -.-'