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 7678405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:38:23+00:00 2026-05-31T17:38:23+00:00

i have a php that responds to an ajax and inserts a row into

  • 0

i have a php that responds to an ajax and inserts a row into database, this is the code

if($action == "insertCalendarEvents") {
        $calendar_group = $_GET["calendar_group"];
        $event_name = "'" . $_GET["event_name"] . "'";
        $event_datestart = "'" . $_GET["event_datestart"] . "'";
        $event_datestop = "'" . $_GET["event_datestop"] . "'";
        $event_timestart = $_GET["event_timestart"] != "" ? "'" . $_GET["event_timestart"] . "'" : "null";
        $event_timestop = $_GET["event_timestop"] != "" ? "'" . $_GET["event_timestop"] . "'" : "null";
        $event_info = "'" . $_GET["event_info"] . "'";

        require_once("connect.php");
        $query = "INSERT INTO calendar_events (calendar_group, event_name, event_datestart, event_datestop, event_timestart, event_timestop, event_info) VALUES (" . $calendar_group . ", " . $event_name . ", " . $event_datestart . ", " . $event_datestop . ", " . $event_timestart . ", " . $event_timestop . ", " . $event_info . ")";
        $result = pg_query($connect, $query);
        if(!$result)
            die("error 1"); // query error
    }

what i want to achieve it to make this code to return the id that the database auto-incremented and echo it back to the ajax function, the problem is that i cant get the last id because someone else might insert data after me and get the wrong id..
i would be rly happy to know if there is a workaround on this issue
Thanks in advance, Daniel!

EDIT: i want to add that i am using PostgreSQL as database, maybe it has a module to do that

  • 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-31T17:38:24+00:00Added an answer on May 31, 2026 at 5:38 pm

    Checking http://wiki.postgresql.org/wiki/FAQ#How_do_I_get_the_value_of_a_SERIAL_insert.3F, it seems you can do queries like:

    INSERT INTO person (name) VALUES ('Blaise Pascal') RETURNING id

    I’m assuming you call pg_fetch_assoc() on the query resource and treat it like a SELECT?

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

Sidebar

Related Questions

I have PHP scrip that goes like this: if ($cost_frm < $cost){ echo <script
I have the following code: for (i=1;i<=pages;i++) { $('#procout').append(Processing Page#+i+<br />); $.ajax({ url: 'processor.php',
Ok, so I have code that posts to my php site, but I want
I have this code that works ok when search button is pressed, but if
I have php script that creates a temporary watermark image for users that are
I have php scripts that do things like register, login, upload. I would like
I have a php that makes some maintenance operations in my web and I
I have a php file somejson.php that echos a json encoded array {jsonone:first json,jsontwo:second
I have PHP configured so that magic quotes are on and register globals are
I have a php server that is running my domain name. For testing purposes

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.