0

Hello ! This code below should display me all the alert boxes but , unfortunetly it display only 3 ( without the alert inside the $.post function ) and i really don't see a problem in my code .. What is wrong?

JS

var uname = name.val();
                alert( uname );
                alert('merge1');
                $.post('validateuser.php' , {names:uname} , function(data){

                    alert('merge2');

                });
                alert('merge3');    

PHP

$name = &$_POST['names'];

if($name != ""){
    include('config.php');

    $username = mysql_query("SELECT username FROM users WHERE username='$name'");
    $count = mysql_num_rows($username);
    if($count != 0){
        echo 0;
    }else{
        echo 1;
    }

}

may the path is wrong .. so , my folder looks like : folder/core/validateuser.php & folder/core/script.js (location of JS script )

3
Contributors
7
Replies
21
Views
4 Years
Discussion Span
Last Post by MWEB
0

If you are not getting the merge2, the problem must be in the PHP script. You can either debug that, or use the done and fail events available from jQuery 1.5+, as described here.

Is there a reason you are using a reference in line 1 of the script, it shouldn't be necessary.

Edited by pritaeas

0

in line 1 of PHP & JS , no .. it is not necessary but it keeps the code clean for me:)

I used .fail function and it ( expected ) gives me the alert box Error ( code below )

JS

var uname = name.val();
                alert('merge1');
                $.post('validateuser.php' , {names:uname} , function(data){

                    alert('merge2');

                }).fail( function(){
                    alert('error');
                });
                alert('merge3');

What should i do with the php code?

PHP (i've test it with this: $name = "Andrew" ,in SQL(phpmyadmin) i've created a record Andrew and the result was 0 , after changing $name = "Andrew1" the result was 1 , so it works .. what's the problem?

<?php 

$name = &$_POST['names'];

if($name != ""){
    include('config.php');

    $username = mysql_query("SELECT username FROM users WHERE username='$name'");
    $count = mysql_num_rows($username);

    if($count != 0){
        echo 0;
    }else{
        echo 1;
    }

}


?>
0

No , the reference is not causing the issue ..

0

So , first appears alert('merge1'); after close this appears alert('merge3') and after closing this one the fail alert appears [ alert(error); ]

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.