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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:05:45+00:00 2026-05-25T23:05:45+00:00

I have a form page in which either an INSERT or an UPDATE query

  • 0

I have a form page in which either an INSERT or an UPDATE query is submitted, depending on the presence/absence of an ID (and when there’s an ID it’s used to retrieve the record and pre-populate the form). In either case, the processing is in form.php so the form’s action is itself (action="/form.php">). My problem is that when form.php reloads post-submit, the URL has an empty ID so the page enters ‘INSERT’ mode, rather than ‘UPDATE’ mode. What’s the best practice way to resolve this?

  1. What operator/condition should I add to this ‘if’ …

    if (isset($_GET['ID']) && is_numeric($_GET['ID'])) {

… to include post-submit empty ID URL (i.e., form.php?ID=)

OR,

  1. How do I pass `$newID = mysql_insert_id();1 to the form’s action? (I’ve tried a number of variations here w/out success)

    $newID = mysql_insert_id();
    … [ snip ] …
    <form method="post" action="/html/form.php?ID=<?php echo $newID; ?>">

I’m reading about hidden inputs and sessions but it’s not yet clear to me how to use either to solve this problem. Lastly, since it isn’t absolutely necessary that I reload the form page, I’m increasingly tempted to move the form processing/db queries to another page (e.g., process.php) to hopefully simplify; any opinions on this? What’s best/common practice?

Many thanks in advance,

svs

  • 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-25T23:05:45+00:00Added an answer on May 25, 2026 at 11:05 pm

    Common practice should be to keep data posting separate from data displaying. This prevents accidental adds on a user’s first arrival to the page as well as accidental double-posts if the user hits refresh.

    In addition, keeping the logic separate makes the code more readable and maintainable in the future.

    The approach you should probably look for is:

    view.php?ID=<record to view> // Only displays a record already in the DB
    add.php                      // The add record form with action="process_add.php"
    process_add.php?Field1=<>&Field2=<>... // Receives data from add.php, puts it in
                                           // the database and then forwards back to
                                           // view.php or add.php as you see fit.
    

    EDIT: While I have GET arguments on process_add.php, they are only there to demonstrate that they are being passed. They should be sent as POST arguments in and actual implementation.

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

Sidebar

Related Questions

I have a page which should show a form with checkboxes, post back if
I have a ASP.NET page which has a form on it. It also has
I have an ASP.NET page which has a script manager on it. <form id=form1
I have a child page LoginContent.aspx which contains a login form. If the user
I have a html page with a form. The form has Div which gets
I have a user input page which loads different forms with ajax depending on
I have this login form which uses AJAX to query a database for checking
I have a form which I'm putting in a IFrame within a page. The
I have a form page in PHP that reads a DBF, and conditionally converts
I have a form on a page where the user has inputs to edit

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.