I have a main page where you fill in some data. After you click on a link "create" it will call ajax to insert new record into mysql database (with data from main page). The mysql table where I'm inserting this new record has an auto_increment primary key and I need to know this key on page where the "create" link is redirecting. So to show it in a short simplified example I have something like this:
index.php has a link Create index.php has also this jquery $("#create").click($.ajax({ url: "create.php", cache: false, data: { ... some data from index.php ... } }));
create.php inserts record into database and after that does this $_SESSION["id"] = mysql_insert_id();
new.php needs to get this id from $_SESSION["id"]
When I tried to call ajax (insert record) outside of click event (so immediately after the main page has loaded) before I actually clicked the link it worked perfectly. However this way it works kind of randomly. Sometimes it does sometimes it doesn't and it never ever worked in Google Chrome this way...
I'm using session_start() properly in the beginning of the documents so there's no problem in this.
Thank you very much for any help I'm struggling many days with this and at last I located that the problem comes from this ajax call position in click event but I have no idea how to fix it. I guess that I'm missing some knowledge about how exactly do page redirecting and click event work together with ajax.