Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7513681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:15:37+00:00 2026-05-30T00:15:37+00:00

I have a main page where you fill in some data. After you click

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T00:15:39+00:00Added an answer on May 30, 2026 at 12:15 am

    First your session has to be started in the index.php page so new.php and create.php will receive the session ID in the session cookie. You could theoretically call $.ajax then change the window location right after it. However this doesn’t guaranty you that create.php as finished execution (ie. created the line you want and insert the data you want into the session which should be stored in your database). This can result in a race condition which you are experiencing.

    To fix this, you simply have to change your window URL in a function on Ajax call success like :

    $("#create").click($.ajax({ url: "create.php", cache: false, data: { ... some data from index.php ... }, success: function() { window.location = 'new.php'; } }));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On my main page I have this jquery code which does an ajax call
I have a grid view in my main page and I display some data
Firstly, i have a grdData at my main page. After choosing the data i
I have a main page from where I am making a call to load
I have a #main div that I'd like to fill the page between the
I Have a php form page where users fill the data and process page
I am using jQuery for a simple website and have a main page 'index.html'
I have in the main page with two principal parts : in the left
The Idea I have a main PHP page that loads content in DIV's from
I have a page (main.php) which loads content from an external PHP file (rpc.php).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.