I am having problem on this code of mine, I made a short javascript pop-up notice everytime a user logs a incorrect password or a correct pass, and when I typed the correct username and password, it is still invalid but when i delete these codes:


it logs in well and there's no little security on my login... Please help me guys!

PHP Code:

$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password=""; // Mysql password 
$db_name="db"; // Database name 
$tbl_name="members"; // Table name

mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");



$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

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


if($count == '1') {

echo '1';
  echo '0';

Javascript Login:

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$.post("checklogin.php",{ myusername:$('#myusername').val(),mypassword:$('#mypassword').val()} ,function(data)
if(data == '1')
$('.message').html('<p>Success - Redirecting...</p>');
$('.message').html('<p>Login Failed - Please Try Again</p>');
return false;

Login Form:

<center><div class="message" style="color:red;font-weight:bold"></div></center>
			<form id="login_form" name="form1" method="post" action="" class="login">
				<h2>Login</h2><br class="spacer" />
				<label>Username: </label><br class="spacer" />
				<input name="myusername" type="text" id="myusername" /><br class="spacer" />
				<label>Password: </label><br class="spacer" />
				<input name="mypassword" type="password" id="mypassword" /><br class="spacer" />
				<input name="" type="checkbox" value="" class="check" /><p>Remember my password</p>
				<input name="button" id="button" value="Submit" type="image" src="images/login_btn.jpg" title="Login" class="loginBtn" />
				<!-- <a href="#" class="registerBtn"><img src="images/register_btn.jpg" title="Register"/></a> -->
			</form><br class="spacer" />

To solve this problem simply delete the session_register() function wherever you have used it and also at the top of each page (on line 1) place the following.

<?php session_start();

That should solve it.

It doesn't work, I put the code that you gave me in the first line below the <?php and also deleted the session_register, and still no luck, any other solutions? Thanks by the way.

Do you have cookies enabled because having cookies disabled will disable sessions. If you want to know how to use sessions with cookies disabled then click here.

Holy Epic! Thanks man now it works! SOLVED!

use this $_SESSION=$myusername; in place of


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.