Jump to content

Login Page help????


dave_55

Recommended Posts

Hi everyone,

 

Could someone look at my code please, ive created a simple login page but it doesn't seem to be working as it should.  I get my first page up which asks for your login details. i enter my correct details that i have already stored in my sql table but it won't display the login success page or the password incorrect page if its wrong.....All it does is goes to the checklogin.php and then nothin is displayed, it doesn't give me errors in my browser either so i don't know whats wrong??????

 

Can anyone help please????

 

My Code:

 

Login.php:

 

 

<head>

 

<title>login page</title>

 

<style type = "text/css">

#loginform {

border 2px solid #600;

background-colour: #FFC;

width: 280px

}

 

forms {

margins: 5px;

}

 

label {

display: block;

width: 90px;

float: left;

clear: both;

}

 

label, input {

margin-bottom: 4px;

}

   

    </style>

</head>

<body>

 

<div id ="loginform">

<form method="post" action="checklogin.php" name="form1">

    <label for = "username">Username:</label>

        <input type="text" name="myusername" id="username" />

        <label for = "password">Password:</label>

<input type="text" name="mypassword" id="password" />

        <input type="submit" name="submit" value="Login" />

       

 

 

</div>

 

 

</body>

</html>

 

Checklogin.php

<?

$host = "localhost"; //login to the server

$username = "dave"; //username login

$password = "*****"; //password login

$db_name = "test site"; //database name change to lincoln

$tbl_name = "members"; //members tabel

 

mysql_connect($host, $username, $password) or die("can't connect");

mysql_select_db($dbname) or die("Could not select lincoln rugby");

 

 

$myusername = $_POST['myusername'];

$mypassword = $_POST['mypassword'];

 

$sql = "SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";

$result = mysql_query($sql);

 

$count = mysql_num_rows ($result);

 

if ($count==1) {

session_register("myusername");

session_register("mypassword");

header("location:login_success.php");

}

else {

echo "Wrong Username or Password";

}

 

?>

login_success.php

 

<?

session_start();

if (!session_is_registered(myusername)) {

header ("location:login.php");

}

?>

 

<html>

<head><title>welcome</title>title>

</head>

<body>

<h1>Login Successsful</h1>

 

<p>

<a href="logout.php">Log Out!</a>a></p>

 

</body>

</html>

 

logout.php

<?

session_start();

session_destroy();

?>

 

<html>

<head><title>Thanks</title>

</head>

<body>

<h1>You've Logged Out</h1>

 

 

</body>

</html>

Link to comment
Share on other sites

Add the following to the top of checklogin.php:

 

ini_set('display_errors', 1);
error_reporting(E_ALL | E_STRICT);

session_start();

 

The first 2 lines should display any errors (which will allow you to narrow down any other issues) and the last line is required at the top of checklogin.php since you are using session_register in it.

Link to comment
Share on other sites

try using

<?php
session_start();
// Check user inputs against database.
mysql_select_db($database_db, $db);
$query_check = sprintf("SELECT * FROM $tbl_name WHERE username = '$myusername'");
$check = mysql_query($query_check, $db) or die(mysql_error());
$row_check = mysql_fetch_assoc($check);
$totalRows_check = mysql_num_rows($check);

// If the passwords match.
if($mypassword == $row_check['password']) 

{
   session_register("myusername");
   session_register("mypassword");
   header("location:login_success.php");
   }

else {
echo "Wrong Username or Password";
   }
?>

 

instead of

 

<?php
$sql = "SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result = mysql_query($sql);

$count = mysql_num_rows ($result);

if ($count==1) {
   session_register("myusername");
   session_register("mypassword");
   header("location:login_success.php");
   }
else {
   echo "Wrong Username or Password";
   }
?>

 

also i see that ur $db_name = "test site"; 

try something with out a space

 

edit: i edited my code to inlcude the session_start();

 

please try it again

Link to comment
Share on other sites

alirght replace checklogin php with this

(make sure to re edit your pw's and names and stuff, also try to remove spaces in the database name)

<?php
$host = "localhost";         //login to the server
$username = "dave";         //username login
$password = "*****";         //password login
$db_name = "test site";         //database name change to lincoln
$tbl_name = "members";         //members tabel

$db = mysql_pconnect($host, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR); 
// Check user inputs against database.



$myusername = $_POST['myusername'];
$mypassword = $_POST['mypassword'];
session_start();




mysql_select_db($db_name, $db);
$query_check = sprintf("SELECT * FROM $tbl_name WHERE username = '$myusername'");
$check = mysql_query($query_check, $db_name) or die(mysql_error());
$row_check = mysql_fetch_assoc($check);
$totalRows_check = mysql_num_rows($check);

// If the passwords match.
if($mypassword == $row_check['password']) 

{
   session_register("myusername");
   session_register("mypassword");
   header("location:login_success.php");
   }

else {
echo "Wrong Username or Password";
   }
?>

Link to comment
Share on other sites

ok first if u are getting a blank page, check error.log in the apache folder,

 

if no errors then try this:

 

Checklogin.php

<?php
session_start();


$host = "localhost";         //login to the server
$username = "dave";         //username login
$password = "*****";         //password login
$dbname = "lincoln";         //database name change to lincoln
$tbl_name = "members";         //members tabel

mysql_connect($host, $username, $password) or die("can't connect: ".mysql_error());
mysql_select_db($dbname) or die("Could not select lincoln rugby: ".mysql_error());


$myusername = $_POST['myusername'];
$mypassword = $_POST['mypassword'];

$sql = "SELECT `username` FROM `$tbl_name` WHERE `username`='".mysql_escape_string($myusername)."' and `password`='".mysql_escape_string($mypassword)."'";
$result = mysql_query($sql) or die("Error in query ($sql): ".mysql_error();

if (mysql_num_rows ($result) >= 1) {
   $_SESSION['myusername'] = $_POST['myusername'];
   $_SESSION['mypassword'] = $_POST['mypassword'];
   header("location: login_success.php");
   }
else {
   echo "Wrong Username or Password";
   }

?>

 

hope this helps,

Link to comment
Share on other sites

ok changed it to this: and getting this error:  Warning: mysql_pconnect() [function.mysql-pconnect]: Access denied for user 'dave'@'localhost' (using password: YES) in C:\wamp\www\test site\checklogin.php on line 10

 

Fatal error: Access denied for user 'dave'@'localhost' (using password: YES) in C:\wamp\www\test site\checklogin.php on line 10

 

<?php

$host = "localhost";        //login to the server

$username = "dave";        //username login

$password = "ozxoka";        //password login

$db_name = "logintest";        //database name change to lincoln

$tbl_name = "members";        //members tabel

 

$db = mysql_pconnect($host, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR);

// Check user inputs against database.

 

$myusername = $_POST['myusername'];

$mypassword = $_POST['mypassword'];

session_start();

 

mysql_select_db($db_name, $db);

$query_check = sprintf("SELECT * FROM $tbl_name WHERE username = '$myusername'");

$check = mysql_query($query_check, $db_name) or die(mysql_error());

$row_check = mysql_fetch_assoc($check);

$totalRows_check = mysql_num_rows($check);

 

// If the passwords match.

if($mypassword == $row_check['password'])

 

{

  session_register("myusername");

  session_register("mypassword");

  header("location:login_success.php");

  }

 

else {

echo "Wrong Username or Password";

  }

?>

Link to comment
Share on other sites

ok fixed that had a capital D instead of d on my username....now thats done i get thiserror from the code....

 

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\wamp\www\test site\checklogin.php on line 19

Link to comment
Share on other sites

Actually tbh i should of told him what the error means and let him figure it out rather than give him the answer, your sloppy code is what we actually should give out to people who are new to this, they need to learn, they wont learn with perfect code given to them everytime ;)

 

 

If you ever get 'sloppy' code from someone, it will usually work if you can figure out the error it makes, there are only a certain number of errors and they are all documented, google it.

Link to comment
Share on other sites

thats how i learned php, i'ms till kinda a noobie but i've developed a shit load of apps, i created a cms,

 

but uniflare,

 

i'm having a problem with an app i'm creating right now

 

do you know anything about js/php togeather?

 

i need to echo a javascript in line function can you please help?

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.