sevaara Posted April 23, 2012 Share Posted April 23, 2012 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? -.-' Quote Link to comment Share on other sites More sharing options...
wigwambam Posted April 23, 2012 Share Posted April 23, 2012 If you're seeing PHP code then it sounds like your server isn't configured for it. Create a new file, call it test.php Add this 1 line of code: <?php phpinfo(); ?> Access the page, what does it display? Quote Link to comment Share on other sites More sharing options...
sevaara Posted April 23, 2012 Author Share Posted April 23, 2012 If you're seeing PHP code then it sounds like your server isn't configured for it. Create a new file, call it test.php Add this 1 line of code: <?php phpinfo(); ?> Access the page, what does it display? It displays a white blank page. I just tested the login page in Internet Explorer and it tried to download the login.php file when I click login. Here's what it displays when I try to login on Firefox 0){ echo "Username & Password correct (Logged in)"; } else { echo "That user doesn't exist"; } } else { echo "Please enter a username and password!"; } ?> Quote Link to comment Share on other sites More sharing options...
wigwambam Posted April 23, 2012 Share Posted April 23, 2012 Either the server doesn't run php or your editor is saving the file as test.php.html ? What host/editor are you using? Quote Link to comment Share on other sites More sharing options...
sevaara Posted April 23, 2012 Author Share Posted April 23, 2012 Either the server doesn't run php or your editor is saving the file as test.php.html ? What host/editor are you using? Localhost with Xampp, Xampp says Apache server and MySQL are running. The file definitely isn't test.php.html so this is a server config thing, any idea what it could be? Quote Link to comment Share on other sites More sharing options...
wigwambam Posted April 23, 2012 Share Posted April 23, 2012 Sorry sevaara, not too familiar with Xampp but looks like a config issue, hope someone else can help you. Quote Link to comment Share on other sites More sharing options...
sevaara Posted April 23, 2012 Author Share Posted April 23, 2012 Sorry sevaara, not too familiar with Xampp but looks like a config issue, hope someone else can help you. Ah okay, appreciate your input either way, at least I know it's a server config thing and not a code error. Quote Link to comment Share on other sites More sharing options...
xyph Posted April 23, 2012 Share Posted April 23, 2012 You aren't accessing the file through the web-server, that's probably why IE is trying to download it. The other browsers are trying to parse it as HTML, more than likely. Access the page through http://localhost/file.php, assuming file.php is in the base 'htdocs' or 'www' folder. Quote Link to comment Share on other sites More sharing options...
sevaara Posted April 23, 2012 Author Share Posted April 23, 2012 You aren't accessing the file through the web-server, that's probably why IE is trying to download it. The other browsers are trying to parse it as HTML, more than likely. Access the page through http://localhost/file.php, assuming file.php is in the base 'htdocs' or 'www' folder. This is what I get Object not found! The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again. If you think this is a server error, please contact the webmaster. Error 404 localhost 04/23/12 21:13:12 Apache/2.2.21 (Win32) mod_ssl/2.2.21 OpenSSL/1.0.0e PHP/5.3.8 mod_perl/2.0.4 Perl/v5.10.1 Quote Link to comment Share on other sites More sharing options...
xyph Posted April 23, 2012 Share Posted April 23, 2012 I can't help you locate files on your own hard drive :/ You have to make sure the PHP files are in a folder the web server can access (somewhere in either htdocs or www, whichever your webserver uses), and that you use the correct file names. If the script is in htdocs/deep/path/file.php, you will use http://localhost/deep/path/file.php Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 23, 2012 Share Posted April 23, 2012 I've only used WAMP but I know when you set it up you can just go to localhost and it will show you everything you have in www along with links to phpmyadmin etc. Does XAMP do this too? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.