Jump to content

Login page issues


sevaara

Recommended Posts

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? -.-'

Link to comment
Share on other sites

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!"; } ?>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.