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?
1

1 Answer 1

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"];
Sign up to request clarification or add additional context in comments.

Comments

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.