Databases Reference
In-Depth Information
4.3.11 Inserting data
The users of the inventory system in our example need to be able to add a new
product into the database. The user might have the session shown in
Example 4-13.
Example 4-13 Sample session adding a product into inventory program
-------------------------------------------------
SIMPLE INVENTORY MANAGEMENT SYSTEM
1. Add New Product
2. Update Product Info (Quantity or Location)
3. Query Product
4. Exit
Enter option: 1
-------------------------------------------------
Add A Product
Enter Product ID : 101-101-10
Enter Quantity : 50
Enter Location : Warehouse
Product successfully added.
-------------------------------------------------
When the user chooses the option to add a new product, this will invoke the
add_product() function within the application. We need to write an INSERT
statement to add a record to the INVENTORY table using the values supplied by
the user.
The complete definition of the add_product() function is shown in Example 4-14.
Example 4-14 Complete definition of the add_product() function
void add_product(void)
{
printf("-------------------------------------------------\n");
printf(" Add A Product \n\n");
printf(" Enter Product ID : ");
scanf("%s", &PID);
printf(" Enter Quantity : ");
scanf("%d", &quantity);
printf(" Enter Location : ");
scanf("%s", &location);
Search WWH ::




Custom Search