jrobert755
New Member
- Messages
- 15
- Reaction score
- 0
- Points
- 0
here is my problem. i am creating a login script with html and ajax that will check if the information is correct. but, it is targeting itself instead of the intended webpage. how can i fix it. here is the code:
login.php
	
	
	
		
tester.php
	
	
	
		
			
			login.php
		HTML:
	
	<html>
<script language="javascript" type="text/javascript">
<!-- 
        //Browser Support Code
        function ajaxFunction(){
            var ajaxRequest;  // The variable that makes Ajax possible!
    
            try{
                // Opera 8.0+, Firefox, Safari
                ajaxRequest = new XMLHttpRequest();
            } catch (e){
                // Internet Explorer Browsers
                try{
                    ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
                } catch (e) {
                    try{
                        ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
                    } catch (e){
                        // Something went wrong
                        alert("Your browser broke!");
                        return false;
                    }
                }
            }
            // Create a function that will receive data sent from the server
            ajaxRequest.onreadystatechange = function(){
                if(ajaxRequest.readyState == 4){
                    var ajaxDisplay = document.getElementById('display');
                    ajaxDisplay.innerHTML = ajaxRequest.responseText;
                }
            }
            var username = document.getElementById('username').value;
            var password = document.getElementById('password').value;
            var queryString = "?username=" + username;
            ajaxRequest.open("GET", "tester.php" + queryString, true);
            ajaxRequest.send(null); 
        }
        //-->
</script>
<form>
Username: <input name="username" type="text" /><br />
Password: <input name="password" type="password" /><br />
<input type="submit" onclick='ajaxFunction()' />
<div id="display"></div>
</form>
</html>
		PHP:
	
	<?php
    $username=$_GET['username'];
    $password= sha1($_GET['password']);
    if(!get_magic_quotes_gpc()) {
        $username= addslashes($username);
    }
    
    include("config.php");
    
    $result=mysql_query("SELECT * FROM username WHERE username='$username'") or die(mysql_error());
    if(mysql_num_rows($result) == "1")
    {
        $test=mysql_fetch_array($result);
        $testa =$test['password'];
        $actkey= $test['activated'];
        if($actkey == "1")
        {
            if($password == $testa) {
                echo "Success!";
            } else {
                echo "Incorrect information. Please try again";
            }
        }
        else
        {
            echo "Your account has not been activated.";
        }
    }
    else
    {
        echo "You entered an incorrect username. Please try again.";
    }
?> 
				 
 
		