0

I have a home.php through which i send some data which gets inserted into DB, which is done by making an ajax call to another php page, lets say function.php and a unique id is generated against the entry and stored in a variable $id.

When the user leaves the home.php page I want to delete the particular entry that was inserted into the DB, by making another ajax call to same function.php, but the problem is that the $id that was previously generated is lost as function.php is reloaded. Declaring a global in home.php doesn't work.

Any idea how can I store the id, so i can retrieve it, when needed.

Some code would be great.

Abhi

0

1 Answer 1

1

Try this way:

Put this on your pages to start a session: session_start(). Then after you inserted data into DB do $_SESSION['sql_insert_id'] = $id - this is assuming you need just one insert per visitor.

Then when you need to delete from the DB you have the $id stored in $_SESSION['sql_insert_id']

You can also close the session after the delete with:

session_unset($_SESSION['sql_insert_id']);
session_destroy();
Sign up to request clarification or add additional context in comments.

3 Comments

i tried using session but when i try to reload the page, it takes a lot of time to reload, dunno y..
Ok, please post your php in your first question so we can check if there is any other problem. Also add error_reporting(E_ALL ^ E_NOTICE);ini_set("display_errors", 1); to the top of your php for debugging.
actually the code is very large to be posted here..i will it a few more try n let ya know

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.