0

I currently have a form in PHP that gets validated using JQuery and the data is submitted to the DB. During the INSERT I'm getting the ID of the user that was inserted.
On success, it redirects the user to the next page which I then want to display the $user_id. I know I should be using get or some other method but unsure how to go about it with my current set up. Any help would be appreciated.

JS

                var submitRequest = $.ajax({
                     type: "POST",
                     url: "submit.php",
                     data: user_data
                });

                submitRequest.done(function(msg)
                {
                    //success
                   // / console.log('success');
                   window.location.href = "nextpage.php";
                });

PHP

$query_user ="INSERT INTO mytable(name,email) VALUES ('".$name."', '".$email."' )";
$sql_user =mysql_query($query_user) or die (mysql_error());
$user_id = mysql_insert_id();

nextpage.php

//How can I get it to display $user_id?
DT.DTDG
  • 765
  • 1
  • 13
  • 31
  • [Why shouldn't I use mysql_* functions in PHP?](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) – Phil Aug 06 '14 at 07:01

1 Answers1

1

Try below :-

PHP

$query_user ="INSERT INTO mytable(name,email) VALUES ('".$name."', '".$email."' )";
$sql_user =mysql_query($query_user) or die (mysql_error());
$user_id = mysql_insert_id();
echo $user_id;

JS

submitRequest.done(function(msg)
                {
                    //success
                   // / console.log('success');
                   window.location.href = "nextpage.php?id="+msg; // msg will consist userid
                });

nextpage.php

$userid = $_GET["id"];
Khushboo
  • 1,819
  • 1
  • 11
  • 17