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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:54:27+00:00 2026-05-30T20:54:27+00:00

I am making quite a large online points/purchasing system in PHP and just have

  • 0

I am making quite a large online points/purchasing system in PHP and just have a fundamental question.

All the relevant stuff is on a single PHP page within the site, with “includes” from other parts of the site such as shopping cart, points review, products etc…, but throughout the page there are stages where the user clicks a form submit button to pass values via $_POST.

As there is a main page for all this stuff, I have a part at the top of the page where it takes all the POST values and makes decisions based upon them, like so:

if($_POST['add']) {
    $product_id = $_POST['add'];
}

if($_POST['remove']) {
       $rid = $_POST['id'];
       $cart->del_item($rid);                   
}
if($_POST['empty']){    
   $cart->empty_cart();
} 
if($_POST['purchase']) {
   foreach($cart->get_contents() as $item) {
     $sql="INSERT INTO wp_scloyalty_orders VALUES (".$user_id.", ".$item['id'].")";
     $result=mysql_query($sql);
   }

   $cart->empty_cart();
   unset($_SESSION['cart']);            
}       
if($_POST['add']) {
   query_posts('post_type=prizes&showposts=-1&p='.$product_id.''); 

    while (have_posts()) : the_post(); 
   $my_meta = get_post_meta($post->ID,'_my_meta',TRUE);


   if($calctotalnew > $my_meta['pointsvalue']){
      $cart->add_item(get_the_id(), 1, $my_meta['pointsvalue'], get_the_title());
   } else {
      echo 'You do not have sufficient points to redeem this product...';
   }

endwhile; 
wp_reset_query();  
}

So my question is… is this really a good way to organize a system, having the form actions go to the same page that the form is on, and have a load of IF statements to decide what to do with the POST values?

Thanks! 🙂

  • 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-30T20:54:29+00:00Added an answer on May 30, 2026 at 8:54 pm

    it’s generally best to capture separate POST calls (grouped by type) in separate actions. I usually go as follows:

    page 1 has a form, which will submit to eg. product.php?action=add. In product.php you can route the ‘add’ action to the function add_product() (or whatever). Then when the product is added, just header the user back to the main page (or whatever page you’d like). This immediately tackles the problem with refresh-posts (user refreshing the page which will send the same data again).

    following mvc imagine you have a controller Product which handles all the product actions. The skeleton could look like this (assuming function action_x will be executed when yoursite.com/product/x is requested):

    class Product_Controller {
        function action_show() {
        }
    
        function action_update() {
        }
    
        function action_delete() {
        }
    }
    

    if your framework supports a default action of some sort you could route your actions:

    function action_default() {
        if(method_exists(array($this, 'action_'. $_POST['action']))) {
            return call_user_method('action_'. $_POST['action'], $this);
        }
    }
    

    ofcourse the same can be achieved without controller classes;

    if(function_exists('action_'. $_POST['action'])) {
        call_user_func('action_'. $_POST['action']);
    }
    
    function action_show() { }
    ...
    

    and to illustrate the discussion in the comments;

    function action_update() {
        // do some update logic, query an UPDATE to mysql etc.
        if($result) {
            // optionally save a success message
            Message::add('Your record has been updated');
            header('Location: main_page.php'); // or another intelligent redirect function
        } else {
            Message::add('Sorry, something went wrong');
            header('Location: error_page.php'); // or also main_page
        }
    }
    

    This will also keep your code cleaner, as updating/adding/deleting stuff is radically different from showing stuff, this will prevent you from mixing up stuff. You could even call the show function from within the update function if you want to skip the redirect.

    But in the end it’s a matter of choice, led by pragmatism or your framework 😉

    I hope this’ll explain everything a bit, don’t hesitate to ask for clarification

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

Sidebar

Related Questions

I have been making HTML/PHP/MySQL database apps for quite a while now. I have
I was making a form that is um... quite large and all inputs consist
I have a large non-Java EE, JSF-based web app project. Our system is layered
I have followed quite closely some techniques for making little CSS triangles with pseudo
I'm still quite new to Spring, and I've found it to irritating making all
I am quite happy to code out tables by hand when making a database
Possible Duplicate: Making a generic property I'm not quite sure how to do that,
Making echo of a question around the web: Is the syntax for svn:ignore patterns
Making my first steps with NHibernate, I'm trying to have it creating my Tables
All, I'm doing some image manipulation in Scala by making use of BufferedImages and

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.