Hey Guys, So I'm doing a register system and it uses AJAX.
So my JQuery code:
system/js/register.php:
So my problem here is, system/js/register.php returns 'done' but this part don't work :
How may I solve that? Thanks.
So my JQuery code:
Code:
$('#btn-login').click(function() {
var name = $('#login-username').val();
var password = $('#login-password').val();
$.ajax({
url : 'system/js/login.php',
method: 'POST',
data: {
name: name,
password: password
},
beforeSend: function() {
new PNotify({
title: 'Processing...',
text: 'Logging you in...',
type: 'info'
});
},
success:function(result) {
if(result == 'done') {
new PNotify({
title : 'Success!',
text: 'Logged in! Redirecting in a moment...',
type:'success'
});
var delay = 2000;
setTimeout(function(){ window.location = 'index.php'; }, delay);
}
else if(result == 'invalid') {
new PNotify({
title: 'Invalid!',
text: 'Invalid creedentials... Try again!',
type:'error'
});
}
}
});
});
// register
$('#btn-signup').click(function(){
var reg_username = $('#reg_username').val();
var reg_pass = $('#reg_pass').val();
var reg_r_pass = $('#reg_r_pass').val();
console.log(reg_username,reg_pass,reg_r_pass);
$.ajax({
url : 'system/js/register.php',
data:{
reg_username:reg_username,
reg_pass:reg_pass,
reg_r_pass:reg_r_pass
},
method: 'POST',
beforeSend:function() {
new PNotify({
title: 'Registering...',
text: 'Sending data to database...',
type: 'info'
});
},
success: function(result) {
console.log(result);
if(result == "done") {
console.error('hi');
new PNotify({
title: 'Registered!',
text: 'You are registered successfully. For security reasons, please log in with your creedentials..',
type: 'success'
});
}
else if(result == 'password') {
new PNotify({
title: 'Your passwords are incorrect!',
text: 'Your passwords do not match... Check them carefully!',
type: 'error'
});
}
else if(result == 'username') {
new PNotify({
title: 'Your username is incorrect!',
text: 'Your username is taken... Please choose another one! ',
type: 'error'
});
}
}
});
});
system/js/register.php:
PHP:
<?php
include('../config.php');
$username = $_POST['reg_username'];
$password = md5($_POST['reg_pass']);
$r_password = md5($_POST['reg_r_pass']);
if($password !== $r_password) {
echo 'password';
exit;
}
$check_username = mysql_query("SELECT * FROM users WHERE username = '{$username}'");
if(mysql_num_rows($check_username) > 0){
echo 'username';
exit;
}
$query = mysql_query("INSERT INTO users(username,password,rank) VALUES('{$username}','{$password}','1')");
if($query == 1){
echo json_encode('done');
}
?>
So my problem here is, system/js/register.php returns 'done' but this part don't work :
Code:
if(result == "done") {
console.error('hi');
new PNotify({
title: 'Registered!',
text: 'You are registered successfully. For security reasons, please log in with your creedentials..',
type: 'success'
});
}
How may I solve that? Thanks.