PHP CRUD interface Make a simple HTMLPHP website that keeps

PHP CRUD interface:

Make a simple HTML/PHP website that keeps track of books.

Store the title, author, publisher, and ISBN for each book.

Be able to view, add, update, and delete books.

Warn the user to enter all required data fields.

Search by any of the information that has been stored.

All of the data about the books in the collection should be stored in a text file.

Solution

main.cpp


#include \"thrall.h\"

int main() {
   InventoryListType inventoryList;
   string invFileName = \"inventory.txt\";
   int invSize = 0;
   char input;
   cout << \"*******************************************\ \";
   cout << \"Welcome to the Bookstore Management System!\ \";
   cout << \"*******************************************\ \ \";
   while(input != \'6\'){
       displayMenu();
       cin >> input;
       cin.ignore();
       cout << \"++++++++++++++++++++++++++++++++++++++++++\ \ \";
       switch(input){
           case(\'1\'):
               readInventory(inventoryList, invSize, MAX_ITEMS);
               break;
           case(\'2\'):
               addInventory(inventoryList, invSize, MAX_ITEMS);
               break;
           case(\'3\'):
               deleteInventory(inventoryList, invSize, MAX_ITEMS);
               break;
           case(\'4\'):
               updateInventory(inventoryList, invSize, MAX_ITEMS);
               break;
           case(\'5\'):
               sortTitle(inventoryList, invSize, MAX_ITEMS);
               break;
           case(\'6\'):
               writeInventory(inventoryList, invSize, MAX_ITEMS);
               break;
           default:
               cout << \"Invalid option. Please pick again.\ \";
       }
   }
   return 0;
}


thrall.h


// Headers
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

// Constants
const int MAX_ITEMS = 100;
const int FIELD_COUNT = 6;
const string INVENTORY_FILE = \"inventory.txt\";

// Types
struct Book {
   int isbn;
   string title;
   string author;
   string publisher;
   int quantity;
   double price;
};
typedef Book InventoryListType[MAX_ITEMS];

// Function Prototypes
void readInventory(InventoryListType, int &, int);
void addInventory(InventoryListType, int &, int);
void deleteInventory(InventoryListType, int &, int);
void updateInventory(InventoryListType, int, int);
void sortTitle(InventoryListType, int, int);
void writeInventory(InventoryListType, int, int);
void displayMenu();
void displayInventory(InventoryListType, int, int);
void displayFeedback(string, string);
bool validateInput();

//*************************************************
// void displayMenu
//*************************************************
void displayMenu(){
   cout << \"----------------------------------\ \"
         << \"Please pick from the menu below:\ \ \"
         << \"1. Read inventory from file\ \"
         << \"2. Add an entry\ \"
         << \"3. Delete an entry\ \"
         << \"4. Update an entry\ \"
         << \"5. Sort inventory\ \"
         << \"6. Write inventory to file and exit\ \"
         << \"----------------------------------\ \ \";
}
void readInventory(InventoryListType inventory, int &size, int maxsize){
   // Create and open an ifstream
   int line = 0;
   ifstream inFile;
   string temp, temp2;
   inFile.open(INVENTORY_FILE.c_str());
   // Loop over the file
   while(!inFile.eof() && size < maxsize){
       getline(inFile, temp);
       switch(line % FIELD_COUNT){
           case(0): // isbn
               inventory[size].isbn = atoi(temp.c_str());
               break;
           case(1): // title
               inventory[size].title = temp.c_str();
               break;
           case(2): // author
               inventory[size].author = temp.c_str();
               break;
           case(3): // publisher
               inventory[size].publisher = temp.c_str();
               break;
           case(4): // quantity
               inventory[size].quantity = atoi(temp.c_str());
               break;
           case(5): // price
               inventory[size].price = atof(temp.c_str());
               size++;
               // reached the end of a record, go to the next one.

       }
       line++;
   }
   // Close the ifstream
   inFile.close();
   cout << \"Inventory loaded (\" << size << \" books)!\ \ \";
   displayInventory(inventory, size, maxsize);
}
void addInventory(InventoryListType inventory, int &size, int maxsize){
   string temp;
   // Check if InventoryListType is full
   if(size < maxsize){
       Book newBook;
       cout << \"Please enter the isbn:\ \";
       getline(cin, temp);
       newBook.isbn = atoi(temp.c_str());
       cout << \"Please enter the title:\ \";
        getline(cin, temp);
        newBook.title = temp.c_str();
       cout << \"Please enter the author:\ \";
       getline(cin, temp);
        newBook.author = temp.c_str();
       cout << \"Please enter the publisher:\ \";
       getline(cin, temp);
        newBook.publisher = temp.c_str();
       cout << \"Please enter the quantity:\ \";
        getline(cin, temp);
        newBook.quantity = atoi(temp.c_str());
       cout << \"Please enter the price:\ \";
       getline(cin, temp);
        newBook.price = atof(temp.c_str());
       inventory[size] = newBook; // add to next spot in inventory
       size++; //increment size
   } else {
       cout << \"The inventory is full, you cannot \"
             << \"add any more books, sorry.\ \";
   }  
}
void deleteInventory(InventoryListType inventory, int &size, int maxsize){
   int bookIndex;
   char input;
  
   if(!size){
       cout << \"There are no books to delete.\ \";
       return;
   }
   cout << \"Please enter the index of the book to delete:\ \";
   displayInventory(inventory, size, maxsize);
   cin >> bookIndex;
   cin.ignore();
   if(!validateInput())
       return;
   if(bookIndex < 0 || bookIndex > size - 1){
       cout << \"Invalid choice!\ \";
       return;
   }
   cout << \"This will remove book [\" << inventory[bookIndex].title
       << \"] do you want to continue (Y|N)?\ \";
   // Collect verification input
   cin.get(input);
   // If verified
   if(toupper(input) == \'Y\'){
       // Loop through inventory starting at bookIndex + 1
       // and move each book down one index. The first move
       // will replace the book at bookIndex.
       displayFeedback(inventory[bookIndex].title, \"deleting...\");
       if(bookIndex < size - 1 && bookIndex < maxsize - 1){ // prevent moving in data from outside array
           for(bookIndex; bookIndex < size - 1 && bookIndex < maxsize - 1; bookIndex++){
               inventory[bookIndex] = inventory[bookIndex + 1];
           }
       }
       // decrement &size  
       size--;
       sortTitle(inventory, size, maxsize);
   }
}
void updateInventory(InventoryListType inventory, int size, int maxsize){
   int bookIndex;
   char input;

   if(!size){
       cout << \"There are no books to update.\ \";
       return;
   }
   cout << \"Please enter the index of the book to edit:\ \";
   displayInventory(inventory, size, maxsize);
   cin >> bookIndex;
   cin.ignore();
   if(!validateInput())
       return;
   if(bookIndex < 0 || bookIndex > size - 1){
       cout << \"Invalid choice!\ \";
       return;
   }
   cout << \"The current quantity of [\" << inventory[bookIndex].title
         << \"] is \" << inventory[bookIndex].quantity << endl;
   // Ask user if they want to enter a new quantity, increment, or decrement.
   // Collect input.
   cout << \"Do you want to add one (I) or remove one (D) or enter a new quantity (N)?\ \";
   cin.get(input);
   // Switch statement based on their input
   switch(tolower(input)){
       case(\'i\'):
           inventory[bookIndex].quantity++;
           displayFeedback(inventory[bookIndex].title, \"updated\");
           break;
       case(\'d\'):
           inventory[bookIndex].quantity--;
           displayFeedback(inventory[bookIndex].title, \"updated\");
           break;
       case(\'n\'):
           cout << \"What is the new quantity?\ \";
           cin >> inventory[bookIndex].quantity;
           cin.ignore();
           if(!validateInput()){
               cout << \"Not a valid quantity!\ \";
               return;
           }
           displayFeedback(inventory[bookIndex].title, \"updated!\");
           break;
       default:
           cout << \"Invalid choice.\ \";
   }
}
void sortTitle(InventoryListType inventory, int size, int maxsize){
   // Implement selectionsort
   // Loop through inventory
   Book temp;
   for(int i = 0; i < size - 1 && i < maxsize - 1; i++){
       for(int j = i + 1; j < size && j < maxsize; j++){
           if(inventory[i].title > inventory[j].title){
               temp = inventory[i];
               inventory[i] = inventory[j];
               inventory[j] = temp;
           }
       }
   }
   displayInventory(inventory, size, maxsize);
}
void writeInventory(InventoryListType inventory, int size, int maxsize){
   if(!size){
       cout << \"There are no books to write out.\ \";
       return;
   }
   cout << \"Writing inventory to the file:\ \";
   sortTitle(inventory, size, maxsize);
   // create and open an ofstream
   ofstream outFile;
   outFile.open(INVENTORY_FILE.c_str());
   // loop through the InventoryListType
   for(int i = 0; i < size && i < maxsize; i++){
       // Output the fields to the file in the
       // correct order.
       outFile << inventory[i].isbn << \'\ \';
       outFile << inventory[i].title << \'\ \';
       outFile << inventory[i].author << \'\ \';
       outFile << inventory[i].publisher << \'\ \';
       outFile << inventory[i].quantity << \'\ \';
       outFile << inventory[i].price << \'\ \';
   }
   // close the ofstream
   outFile.close();
   cout << \"File written, goodbye!\ \ \";
}
void displayInventory(InventoryListType inventory, int size, int maxsize){
   cout << \"\\tCurrent inventory (\" << size << \" books):\ \";
   // loop through the InventoryListType
   for(int i = 0; i < size && i < maxsize; i++){
       // output each i and Book to the screen
       cout << \"\\t\" << i << \". \" << inventory[i].title << endl;
   }
}
void displayFeedback(string bookname, string verb){
   cout << \"\ \\\"\" << bookname << \"\\\" \" << verb << \"\ \ \";
}
bool validateInput(){
   if(cin.fail()){
       cout << \"Invalid choice!\ \";
       cin.clear();
       cin.ignore(100 ,\'\ \');
       return false;
   } else {
       return true;
   }
}


inventory.txt

20451
Brown Family
Mark Lusk
Pearson Publishing
40
45.34
20451
Brown Family
Mark Lusk
Pearson Publishing
40
45.34
20451
Brown Family
Mark Lusk
Pearson Publishing
40
45.34
20451
Brown Family
Mark Lusk
Pearson Publishing
40
45.34
20451
Brown Family
Mark Lusk
Pearson Publishing
40
45.34
20451
Brown Family
Mark Lusk
Pearson Publishing
40
45.34
20451
Brown Family
Mark Lusk
Pearson Publishing
40
45.34
20451
Brown Family
Mark Lusk
Pearson Publishing
40
45.34
20451
Brown Family
Mark Lusk
Pearson Publishing
40
45.34
20451
Brown Family
Mark Lusk
Pearson Publishing
40
45.34
9780316
My First Book
Mason Victor
Little Brown
36
105.99
9780316
My First Book
Mason Victor
Little Brown
36
105.99
9780316
My First Book
Mason Victor
Little Brown
36
105.99
9780316
My First Book
Mason Victor
Little Brown
36
105.99
9780316
My First Book
Mason Victor
Little Brown
36
105.99
9780316
My First Book
Mason Victor
Little Brown
36
105.99
9780316
My First Book
Mason Victor
Little Brown
36
105.99
9780316
My First Book
Mason Victor
Little Brown
36
105.99
9780316
My First Book
Mason Victor
Little Brown
36
105.99
1349877
Story of My Life
Norah M Jones
CreateSpace Independent Publishing Platform
20
18
1349877
Story of My Life
Norah M Jones
CreateSpace Independent Publishing Platform
20
18
1349877
Story of My Life
Norah M Jones
CreateSpace Independent Publishing Platform
20
18
1349877
Story of My Life
Norah M Jones
CreateSpace Independent Publishing Platform
20
18
1349877
Story of My Life
Norah M Jones
CreateSpace Independent Publishing Platform
20
18
1349877
Story of My Life
Norah M Jones
CreateSpace Independent Publishing Platform
20
18
1349877
Story of My Life
Norah M Jones
CreateSpace Independent Publishing Platform
20
18
1349877
Story of My Life
Norah M Jones
CreateSpace Independent Publishing Platform
20
18
1349877
Story of My Life
Norah M Jones
CreateSpace Independent Publishing Platform
20
18
1349877
Story of My Life
Norah M Jones
CreateSpace Independent Publishing Platform
20
18
1349877
Story of My Life
Norah M Jones
CreateSpace Independent Publishing Platform
20
18
1349877
Story of My Life
Norah M Jones
CreateSpace Independent Publishing Platform
20
18
1349877
Story of My Life
Norah M Jones
CreateSpace Independent Publishing Platform
20
18
1349877
Story of My Life
Norah M Jones
CreateSpace Independent Publishing Platform
20
18
1349877
Story of My Life
Norah M Jones
CreateSpace Independent Publishing Platform
20
18
1349877
Story of My Life
Norah M Jones
CreateSpace Independent Publishing Platform
20
18
1349877
Story of My Life
Norah M Jones
CreateSpace Independent Publishing Platform
20
18
1349877
Story of My Life
Norah M Jones
CreateSpace Independent Publishing Platform
20
18
987879
a book
mason
thr
10
10
987879
a book
mason
thr
10
10
987879
a book
mason
thr
10
10
987879
a book
mason
thr
10
10
987879
a book
mason
thr
10
10
987879
a book
mason
thr
10
10
987879
a book
mason
thr
10
10
987879
a book
mason
thr
10
10
987879
a book
mason
thr
10
10
987879
a book
mason
thr
10
10
987879
a book
mason
thr
10
10
987879
a book
mason
thr
10
10
987879
a book
mason
thr
10
10
987879
a book
mason
thr
10
10
987879
a book
mason
thr
10
10
987879
a book
mason
thr
10
10
987879
a book
mason
thr
10
10
987879
a book
mason
thr
10
10
908
alkdjasd
askjdlka
lsakjdas
19
1
908
alkdjasd
askjdlka
lsakjdas
19
1
908
alkdjasd
askjdlka
lsakjdas
19
1
908
alkdjasd
askjdlka
lsakjdas
19
1
908
alkdjasd
askjdlka
lsakjdas
19
1
908
alkdjasd
askjdlka
lsakjdas
19
1
908
alkdjasd
askjdlka
lsakjdas
19
1
908
alkdjasd
askjdlka
lsakjdas
19
1
908
alkdjasd
askjdlka
lsakjdas
19
1
908
alkdjasd
askjdlka
lsakjdas
19
1
908
alkdjasd
askjdlka
lsakjdas
19
1
908
alkdjasd
askjdlka
lsakjdas
19
1
908
alkdjasd
askjdlka
lsakjdas
19
1
908
alkdjasd
askjdlka
lsakjdas
19
1
908
alkdjasd
askjdlka
lsakjdas
19
1
908
alkdjasd
askjdlka
lsakjdas
19
1
908
alkdjasd
askjdlka
lsakjdas
19
1
908
alkdjasd
askjdlka
lsakjdas
19
1
10981
aslkdj
asd
sadk
299
2
10981
aslkdj
asd
sadk
299
2
10981
aslkdj
asd
sadk
299
2
10981
aslkdj
asd
sadk
299
2
10981
aslkdj
asd
sadk
299
2
10981
aslkdj
asd
sadk
299
2
10981
aslkdj
asd
sadk
299
2
10981
aslkdj
asd
sadk
299
2
10981
aslkdj
asd
sadk
299
2
123
the
the
the guys
98
10
123
the
the
the guys
98
10
123
the
the
the guys
98
10
123
the
the
the guys
98
10
123
the
the
the guys
98
10
123
the
the
the guys
98
10
123
the
the
the guys
98
10
123
the
the
the guys
98
10
123
the
the
the guys
98
10
123
the
the
the guys
98
10
123
the
the
the guys
98
10
123
the
the
the guys
98
10
123
the
the
the guys
98
10
123
the
the
the guys
98
10
123

PHP CRUD interface: Make a simple HTML/PHP website that keeps track of books. Store the title, author, publisher, and ISBN for each book. Be able to view, add,
PHP CRUD interface: Make a simple HTML/PHP website that keeps track of books. Store the title, author, publisher, and ISBN for each book. Be able to view, add,
PHP CRUD interface: Make a simple HTML/PHP website that keeps track of books. Store the title, author, publisher, and ISBN for each book. Be able to view, add,
PHP CRUD interface: Make a simple HTML/PHP website that keeps track of books. Store the title, author, publisher, and ISBN for each book. Be able to view, add,
PHP CRUD interface: Make a simple HTML/PHP website that keeps track of books. Store the title, author, publisher, and ISBN for each book. Be able to view, add,
PHP CRUD interface: Make a simple HTML/PHP website that keeps track of books. Store the title, author, publisher, and ISBN for each book. Be able to view, add,
PHP CRUD interface: Make a simple HTML/PHP website that keeps track of books. Store the title, author, publisher, and ISBN for each book. Be able to view, add,
PHP CRUD interface: Make a simple HTML/PHP website that keeps track of books. Store the title, author, publisher, and ISBN for each book. Be able to view, add,
PHP CRUD interface: Make a simple HTML/PHP website that keeps track of books. Store the title, author, publisher, and ISBN for each book. Be able to view, add,
PHP CRUD interface: Make a simple HTML/PHP website that keeps track of books. Store the title, author, publisher, and ISBN for each book. Be able to view, add,
PHP CRUD interface: Make a simple HTML/PHP website that keeps track of books. Store the title, author, publisher, and ISBN for each book. Be able to view, add,
PHP CRUD interface: Make a simple HTML/PHP website that keeps track of books. Store the title, author, publisher, and ISBN for each book. Be able to view, add,
PHP CRUD interface: Make a simple HTML/PHP website that keeps track of books. Store the title, author, publisher, and ISBN for each book. Be able to view, add,
PHP CRUD interface: Make a simple HTML/PHP website that keeps track of books. Store the title, author, publisher, and ISBN for each book. Be able to view, add,
PHP CRUD interface: Make a simple HTML/PHP website that keeps track of books. Store the title, author, publisher, and ISBN for each book. Be able to view, add,

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site