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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:45:28+00:00 2026-06-15T05:45:28+00:00

For my first attempt at programming, I am making a simple webapp with php

  • 0

For my first attempt at programming, I am making a simple webapp with php and MySQL, to enter customer information and store information about orders.

So far I’ve made a form to enter customer information, a page to edit that information and another page to show the different customers, which is all working fine.

I’ve run into a stump when trying to implement the next stage however.

I have an editcustomers page with 3 columns.

  • Column 1 shows a form containing customer information, allowing it to
    be edited.
  • Column 2 allows ordering of products and showing how many products were ordered
  • Column 3 shows the total paid so far, and the total owing.

The code for the page I have at present:

<html>
<?php
$id = $_GET['id'];
require_once('connect.php');
$sth = $dbh->query("SELECT * FROM customers where id = '$id'");
$sth->setFetchMode(PDO::FETCH_ASSOC);
?>

<div id="main">
    <div id="left">
    <form name="myForm" action ="process.php" method ="post" >
    <?php while($row = $sth->fetch()){ ?>
    <p><input type = "hidden" name ="id" value="<?php echo $row["id"] ?>"/>
    <p><input type = "text" name ="firstName" size ="30" value=" <?php echo $row["firstName"]?>"/>
    <p><input type = "text" name ="lastName" size ="30" value="<?php echo $row["lastName"]?>"/>
    <p></p>
    <input type="submit" value="Update" />
    <?php }?>
    </div>

    <div id="mid">
    <p>Amount owed<br />
    <input type = "text" name ="moneyOwed" size ="30" /></p>
    <input type="submit" value="Pay" /> 
    <p>Number of aaaa<br />
    <input type = "text" name ="numAaa" size ="30" /></p>
    <p>Number of bbbb<br />
    <input type = "text" name ="numBbb" size ="30" /></p>
    <p>
    <input type="submit" value="Update" />
    </div>

    <div id="right">
    <b>Total Balance</b>
    <p> Money owed: </p>
        <p> aaa total: </p>
    <p> bbb total: </p>
    <p> Total: </p>
    <input type = "text" name ="pay" size ="20" /></p>
    <input type="submit" value="Make Payment" />
    </div>
<?php
$dbh =null;
?>
</body>
</html>

I have the following database structure:

  • A customers table, basic information like firstname, lastname, etc along with an id field.
  • A products table, listing the different products, only 1 row containing the costs for each product.
  • A purchases table, with an id field , fields like numProductA, numProductB, showing the quantity of each product ordered

The problem I’m having is that in my editcustomerspage, I have a database query to read in information from the customers table to fill the fields in the form in my first column and a separate query to update it if that if the function chosen.

Updating the second formshould be OK, as I could use a hidden field to differentiate forms, however I am unsure how to read the information in from the Customers table and from the Purchases table so that I can populate the fields in my second form..

Part of the problem is that the purchases table may be empty for a given customer, if that customer has not yet placed an order.

I was considering getting rid of the purchases table, and tacking the fields onto the users table which would solve my problem, although I think that is generally considered bad practice?

The products will be fixed in the application, and are not going to change. Even so, would it still be better to have column names cost and name and each products as a record?

What are some approaches I could take to solving this problem?

  • 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-15T05:45:29+00:00Added an answer on June 15, 2026 at 5:45 am

    Even what you currently are doing is considered bad practice because of the columns numProductA, numProductB. What happens when you’ll have 1000 products and a user orders different amounts from all of them. This work only if the list of products is fixed (i.e. coded into the application) and requires a lot of coding.

    You would probably want to create a purchase_item table that has fields like: id, purchase_id, product_id, num_product. It would be like a line on a standard bill: purchase_id identifies which bill the line belongs to; product_id would show the product that line is about and num_product would show the amount (multiplier) on that line.

    In this manner you don’t need to change the code when new products are added to the database.

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

Sidebar

Related Questions

This is my first attempt at responsive design, so I'm keeping it simple. I
Consider my first attempt, a simple type in F# like the following: type Test()
I've already dived into SQL clr programming. Unfortunately my first attempt is troubled. My
I'm brand new at programming and For my first attempt at an app, i'm
( First time programming in PHP. Had some help. Need a bit more. )
First attempt to use this cool site - after searching for 2 hours: So
First day and first attempt at using Scala - so go easy on me!
This is my first attempt to write shorthand if statements however am befuddled by
Because this is my first attempt at an extension method that seems quite useful
this if my first attempt at using streaming for WCF, and I am struggling

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.