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 )

Recommended Answers

All 7 Replies

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.

What if there is only one possible simultaneous alert?

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;
    }

}


?>

Are you sure the reference is not causing the issue, try without the &

No , the reference is not causing the issue ..

What happens when you get rid of every alert except alert2?

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.