SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation How to make JQueryUI dialog login form?

    loginSend.js
    Code:
    $('#loginButton').on('click', function(){ //the id of the submit button = #loginButton
    	
    	var username = $('#userfield').val();
    	var password = $('#passfield').val();
    	
    	if (username.length == 0 || password.length == 0 || password.length < 6) { // checks if username and pass have been entered
    	
    		$('#fillFields').text('*Please enter a valid username/password'); //#fillfields = the div where error message should appear in JQuery UI dialog box
    	} else {
    		
    		//$('#formLogin').text('You have successfully logged in').dialog('close'); //Closes dialog box if logged in currently not in use
    		$.post('loginProcess.php', {username: username, password: password}, funtion(data){ // sends data to loginProcess.php
    		
    			if (data == true){ //checks if the loginProcess has returned true (if the username exists or not)
    				alert('true'); // just to check if the code works, display an alert message
    			}
    	}
    		
    	});
    });
    loginProcess.php
    Code:
    <?php
    
    require 'config.php';
    
    //  LOGIN FORM Process
    
    if (user_exists('super')){ //user_exists() = a user defined function in config.php
    	return true;
    }
    ?>
    <?php
    config.php
    Code:
    function sanitize($data){
    	return mysql_real_escape_string(strip_tags($data));
    }
    
    function user_exists($username){
    
    	$username = sanitize($username);
    	$query = mysql_query("SELECT COUNT(`id`) FROM `users` WHERE `Username` = '$username'");
    	return (mysql_result($query, 0) == 1) ? true : false;
    }
    ?>
    i don't understand what I've done wrong. I'm trying to create a JQuery UI dialog, login form. Normlly when the user types in a username i want it to check if the username exists. But nothing happens. Since i added JQuery Post it doesn't work. How do i get it to display if username exists or not. I think the problem is in $.post because before i added that, my code works, but after i added it it stopped working. It doesn't even display error messages? The whole code just doesn't work.

    How do i fix this and get it to work as intended?

    Thanks

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Code:
    <?php
    
    require 'config.php';
    
    //  LOGIN FORM Process
    
    if (user_exists('super')){ //user_exists() = a user defined function in config.php
    	return true;
    }
    I have not read all your code, but the above seems rather redundant, seeing as user_exists() returns true or false anyways ...

    Try and make it output something more useful:

    PHP Code:
    <?php

    require 'config.php';

    //  LOGIN FORM Process

    if (user_exists('super')){ // boolean
        
    echo 'User found';
    }else{
        echo 
    'User NOT found';
    }
    (for this forum prefer [ PHP ] tags to [ CODE ] )

    HTH


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •