Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-26-2013, 01:44 PM   PM User | #1
ziggy786
New to the CF scene

 
Join Date: Feb 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
ziggy786 is an unknown quantity at this point
Unhappy 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;
}
?>
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
ziggy786 is offline   Reply With Quote
Old 02-26-2013, 03:40 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Quote:
Originally Posted by ziggy786 View Post
. . . Since i added JQuery Post it doesn't work.
Indicating a problem with the JQuery, and not that of PHP. If it worked before adding the JS, the server is capable of processing properly, and its the JS that's not sending the proper data.

PHP wise, you obviously don't want to be hard coding a string into the user_exists function call. There's also a another discrepancy here:
PHP Code:
if (user_exists('super')){ //user_exists() = a user defined function in config.php
    
return true;

You are returning in the dummy main. That may carry no value depending on usage; given what I see here, you should be printing true, not returning it.

I don't do JS programming, but these sure stand out as a problem: username: username, password: password.

Fix up the PHP code first, than fix up the JS.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 03-25-2013, 10:39 AM   PM User | #3
BiztechExperts
New to the CF scene

 
Join Date: Feb 2013
Location: India
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
BiztechExperts is an unknown quantity at this point
From my side

$('#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}, function(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
}

});
}
});
BiztechExperts is offline   Reply With Quote
Reply

Bookmarks

Tags
jquery, login, php

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:11 AM.


Advertisement
Log in to turn off these ads.