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

  • Home
  • SEARCH
  • 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 7902867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:36:57+00:00 2026-06-03T09:36:57+00:00

I am creating a web application and have the following problem. In my application

  • 0

I am creating a web application and have the following problem.

In my application the user is working within a single page, they draw on a canvas. There is a single button called “Save”. This takes the users ID and whatever they have created in the canvas and sends it to a database. This all works fine. The save function resemebles this:

$.ajax({
    url: "/database/write.php",
    type: "POST",     
    data: { 
        docName: name,
        docData: document_Data,
        docMode: "new"
    }, 
    success: function(html) {
        alert("Successfully Saved NEW document");
        set_Mode();
    },          
});

The above AJAX request does send the three values to the PHP script which then successfully creates a new document in the database, what i need to do now is change the application mode from saving a new document to editing the previously saved document. This means that when a user saves again, they will write to the same row, overwriting the previous version of the document.

When i send the data to the write.php it does write the data to the DB and the queries the database for that inserted document and retrieves its unique document ID. with that ID the application can the select that document and overwrite it. To retrieve the document ID from the query, i use the following code in write.php

write.php

$_SESSION['DOCUMENT_ID'] = $DOCUMENT_ID;

This $DOCUMENT_ID is the document ID retrieved from the SELECT query. The script then finishes and transfers control back to the main application page.

Back on the application page i try to retreive the value but it doesnt seem to work. I can retrieve $_SESSION values that were set when the user first accesses the application (id) but now values set by the write.php (DOCUMENT_ID) page. For example, below shows the function called after the AJAX request has been successful:

function set_Mode()
{
    var PHPvar_01 = <?php echo($_SESSION['id']); ?>;
    alert(PHPvar_01); //WORKS FINE

    var PHPvar_02 = <?php echo($_SESSION['DOCUMENT_ID']); ?>;
    alert(PHPvar_02); //DOES NOT WORK.          
};

How should i go about sending data retrieved from the PHP query script to the application, because $_SESSION does not seem to work here.

Thanks for any feedback.

  • 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-06-03T09:36:58+00:00Added an answer on June 3, 2026 at 9:36 am

    at the end of write.php :

    echo json_encode(array('id'=>$_SESSION['id'], 'DOCUMENT_ID'=>$_SESSION['DOCUMENT_ID']));
    

    in your ajax call :

    success: function(data) {
        data = eval('('+data+')');
        alert("Successfully Saved NEW document");
        set_Mode(data.id, data.DOCUMENT_ID);
    },     
    

    this should do the tricks !

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a web application using HTML5 canvas to draw images ( like
I'm creating a web application on Google AppEngine where I want the user to
Java fb API I am creating facebook web application, to create even following is
i have added the following initializer for my asp.net web application :- namespace Learning.DAL
I have a MVC 3 Razor web application that needs to allow creating and
I'm creating a web application installer using WiX. I want to allow the user
I am following MSDN's walkthrough on Creating a Web Site with Membership and User
I am creating a web application framework, in which I am providing support for
I am creating a web application which has a few management screens, where a
I am creating an web application and I at the point that i am

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.