I am trying to get the last inserted id to be displayed in alert box. Can anyone help me out.
I can echo it out but I want to display the ID in alert box and redirect once the user clicks ok. Thank you so much. I am a new php coder.

Recommended Answers

All 2 Replies

Using Google Tag Manager to dramatically simplify the application of cookie regulations
Google Tag Manager is a free tool that helps to simplify the application of cookie regulations. It’s compatible with the iubenda Cookie Solution. You can consult our Google Tag Manager guide here.

Google Tag Manager allows you to avoid tagging scripts as described below, although this is limited to a certain category of scripts – scripts that are not positional/do not define a position. It, therefore, does not handle embed scripts such as those related to advertising banners, youtube video widgets, facebook like buttons etc. Although this method is not a cure-all, we strongly recommend that you use it.

You do not include any code, so it's difficult to see what you've tried and how far or how close you've got.
In js, you can include php variables like this:

var jsId = "<?=$id?>";

or full tags:

var jsId = "<?php echo $id; ?>";

You can then have a script to run an alert:

alert("The id you want is " + jsId);

If you just want a redirect following an alert:

alert("The last record will be shown when you click OK");
window.location.href = "http://www.example.com/showrecords?id=" + jsId;

Or you could just go full throttle and do this:

alert("The last record will be shown when you click OK");
window.location.href = "http://www.example.com/showrecords?id=<?php echo $id;?>";

Alternatively, if you want the user to have a choice in whether to redirect, then offer a confirm box instead of alert - you then need to handle that - plenty of online resources to show you how.

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.