0

in this i am sending the values to adduser.php and after execution completed inserted id will send to index.php.please give the comments

index.php

$.ajax({  
                type: "POST",  
                url: "adduser.php",  
                data: "name="+ name +"&email="+ email,  
                success: function(msg,usrid){  
                alert(msg);
}
})

adduser.php

$q = mysql_query("INSERT INTO `user_login`(fname,email) VALUES('$fname','$email')");
    $id=mysql_insert_id();
echo '0';
echo $id;

contact.php

this response id can be user for next page url as like window.location.href="contact.php?id=$id";if any other option to pass the id value to contact.php

5
  • 2
    What is your question? Commented Apr 26, 2016 at 13:48
  • 1
    Why are you echo '0'; there Commented Apr 26, 2016 at 13:50
  • i want to send adduser.php page $id value to contact.php Commented Apr 26, 2016 at 13:50
  • Do you want to pass the response id from adduser to contact.php, right? Commented Apr 26, 2016 at 13:53
  • correct sir.@JoseRojas Commented Apr 26, 2016 at 13:54

1 Answer 1

1

The callback in the AJAX request receive as argument the response, try this:

$.ajax({  
            type: "POST",  
            url: "adduser.php",  
            data: "name="+ name +"&email="+ email,  
            success: function(usrid){  
                   window.location.href="contact.php?id="+usrid;
                }
})

the zero at your adduser.php is unnecessary.

Sign up to request clarification or add additional context in comments.

2 Comments

How can i get values of two function variables like success: function(usrid,email){ window.location.href="contact.php?id="+usrid; }
in the response at the server side you can echo the data as array encoding as JSON that way you can get from the server as many variables as you need, somthing like echo json_encode(array('usrid' => 1, 'foo' => 'bar')); at the client side, you can obtain this values success: function(response){ response.usrid; response.foo }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.