PHP - Moved: Php (crud)
This topic has been moved to Beta Test Your Stuff!.
http://www.phpfreaks.com/forums/index.php?topic=307377.0 Similar TutorialsOk. I am trying to create a customer tracking database that will allow me to get a handle on my customer support inquiries. To do this I have created a database that will store all of a customers pertinent information and then I plan on creating another table that will be 'Notes' where each note is associated with a customerID. I have created the form fine where I can input the data into the table but I am having issues with the next part. I would like to have a list/menu that will display all of the current users in the database. Then when I click on one of those it will display that information in the form so that I can view it, edit it, or delete it. But I have been stumped for multiple days and other php forums have been absolutely worthless. I know that php can pass a variable name in the address but I have no idea how to do that or how to use it when it's in the address. I know I'm a newb. Please help. I really need to move on from this hurdle. Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> <link href="maxxTraxx.css" rel="stylesheet" type="text/css" /> </head> <body> <?php //Load Database Connectivity and Form Helpers require 'DB.php'; require 'formhelper.php'; //Connect To Database $db = MY CONNECTIVITY IS FINE, HIDING FOR SECURITY PURPOSES if (DB::isError($db)) { die("Cant connect: " .$db->getMessage()); } //Print Message and Quit on Future Database Errors $db->setErrorHandling(PEAR_ERROR_DIE); customerList(); //Main Page Logic if ($_POST['_submit_check']) { foreach($_POST as $key=>$value) { if($key == 'saveCustomer') { //If validate_form() returns errors, show them the form with errors if ($form_errors = validate_formCustomer()) { show_form($form_errrors); } else { //The submitted data is valid, so process it process_formCustomer(); } } if($key =='go') { print $_POST['customerList']; } } }else { //The form wasn't submitted, so display it blank show_form(); } //------------FUNCTIONS--------------------------------------------------------- function show_form($errors = '') { //If the form is submitted, get defaults from submitted parameters if ($_POST['_submit_check']) { $defaults = $_POST; } else { //Otherwise set your own defaults $defaults = ''; } //If errors were passed in, put them in $error_text (with HTML markup) if ($errors) { $error_text = '<tr><td>You need to correct the following errors: '; $error_text .= '</td></tr><ul><li>'; $error_text .= implode('</li><li>',$errors); $error_text .= '</li></ul></td></tr>'; } else { //No errors? Then $error_text is blank $error_text = ''; } $states = array('AL', 'AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'FL', 'GA', 'HI', 'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MD', 'MA', 'MI', 'MN', 'MS', 'MO', 'MT', 'NE', 'NV', 'NH', 'NJ', 'NM', 'NY', 'NC', 'ND', 'OH', 'OK', 'OR', 'PA', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VT', 'VA', 'WA', 'WV', 'WI', 'WY', 'Canada', 'Puerto Rico', 'Australia'); $status = array(1=>'Fine', 2=>'Received', 3=>'In Repair', 4=>'Waiting', 5=>'Shipped'); $months = array(1=>'January', 2=>'February', 3=>'March', 4=>'April', 5=>'May', 6=>'June', 7=>'July', 8=>'August', 9=>'September', 10=>'October', 11=>'November', 12=>'December'); $days = array(); for($i = 1; $i <=31; $i++) { $days[$i] = $i; } $years = array(); for($year = date('Y') , $max_year = date('Y')+5; $year < $max_year; $year++) { $years[$year] = $year; } //Jump out of PHP mode to make displaying all the HTML tags easier but still inside the show_form function ?> <div class="customerForm"> <center><h2>Customer Form</h2></center> <form method="post" action="<?php print $_SERVER['PHP_SELF']; ?>"> <table> <?php print $error_text ?> <tr><td>Last Name</td> <td><?php input_text('customerNameLast', $defaults); ?>, </td> <td>First Name</td> <td><?php input_text('customerNameFirst', $defaults); ?></td> <td>Phone Number</td> <td><?php input_text('customerPhone', $defaults); ?></td></tr></table> <table><tr><td>Address</td> <td><?php input_text('customerAddresss', $defaults); ?></td> <td>City</td> <td><?php input_text('customerCity', $defaults); ?></td> <td>State</td> <td><?php input_select('customerState', $defaults, $states); ?></td> <td>Zip</td> <td><?php input_text('customerZip', $defaults); ?></td></tr></table> <table><tr><td>Email</td> <td><?php input_text('customerEmail', $defaults); ?></td> <td>RMA #</td> <td><?php input_text('customerRMA', $defaults); ?></td> <td>Parts Out</td> <td><?php input_text('customerPartsOut', $defaults); ?></td></tr></table> <table><tr><td>Status</td> <td><?php input_select('customerStatus', $defaults, $status); ?></td> <td>Due Date</td> <td><?php input_select('customerDueMonth', $defaults, $months); ?> <?php input_select('customerDueDay', $defualts, $days); ?> <?php input_select('customerDueYear', $defaults, $years); ?></td></tr></table> <center><?php input_submit('saveCustomer', 'Save Customer'); ?></center> <input type="hidden" name="_submit_check" value="1"/> </form> </div> <?php }//End of the show_form() function function validate_formCustomer() { $errors = array(); return $errors; } function process_formCustomer() { global $db; //Get a unique ID for Customer $customerID = $db->nextID('customerID'); $customerDueDate = $_POST['customerDueYear'].'-'.$_POST['customerDueMonth'].'-'.$_POST['customerDueDay']; $db->query('INSERT INTO Customer (customerID, customerNameLast, customerNameFirst, customerPhone, customerEmail, customerAddress, customerCity, customerState, customerZip, customerStatus, customerPartsOut, customerRMA, customerDueDate) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)', array($customerID, $_POST['customerNameLast'], $_POST['customerNameFirst'], $_POST['customerPhone'], $_POST['customerEmail'], $_POST['customerAddress'], $_POST['customerCity'], $_POST['customerState'], $_POST['customerZip'], $_POST['customerStatus'], $_POST['customerPartsOut'], $_POST['customerRMA'], $customerDueDate)); //Tell the user that we adde a customer print '<center>Added '.htmlentities($_POST['customerNameLast']) .' to the database.</center> <br /><br />'; print '<center><a href="/maxxTraxx/index.php">Back To The Admin</a></center>'; }//End of process_formCustomer function function customerList() { global $db; $qCustomers = $db->query('SELECT customerID, customerNameLast, customerNameFirst FROM Customer'); print '<div class="customerList"><form action="test.php" method="get">'; print '<select name="customerList" size="30">'; while($row = $qCustomers->fetchRow()) { $qAllCustomers[0] = $row[0]; $qAllCustomers[1] = $row[1]; $qAllCustomers[2] = $row[2]; //print $row[0]; //print 'Customer #'.$qAllCustomers[0].' is: '.$qAllCustomers[2].' '.$qAllCustomers[1].''; print '<option value="'.$qAllCustomers[0].'" selected>'.$qAllCustomers[1].', '.$qAllCustomers[2].'</option>'; } print '</select></form></div>'; echo $_POST['customerList']; input_submit('go', 'go'); //return $qAllCustomers; } ?> </body> </html> Hey sorry that I am asking this question, though I have gotten around to learn connecting to a database and also do the retrieve, yet I am not necessarily getting to learn doing INSERT, UPDATE and DELETE the proper way.
The tutorials available are often not best, I have found a good book ("Object Oriented Programming in PHP5") which teaches SELECT, yet not necessarily INSERT, UPDATE and DELETE.
I am really wondering how does one get to learn CRUD with PHP OOP, how did you people learn this? How can I learn INSERT, UPDATE and DELETE as well with PHP OOP? I feel like paying for this on Elance or Fiverr. I am not sure how else to learn this by now, I have tried quite a bit, I have looked at scripts and tutorials and books. And it has just gotten as far as connecting to the database and doing the "fetching" ("SELECT", or also "retrieve"). Too bad that what is available is not necessarily best. Otherwise I would say one could understand the principle quickly and also pick up on a programming language quickly. Please bear with me, I would appreciate suggestions. Hi all, iv benn search for a long time now for a sample on how to create MYSQL based data grid that have some CRUD functionality.. i am using dreamwever and the only thing i can get out of it is using the spray data set that gives me a table with sort abilities but i am looking for something more.. is there a PHP or JS sample of displying the data of MYSQL database that can can do CRUD and search abilities ? thank.. I have three small tables and I'm looking for a clean, light, framework CRUD generator that I can use. Are there any that are small and light that dont require a full blown install like Symphony or phpObject Generator etc... Jared Hi, I am creating my first OOP MVC content management system. I created a CRUD where on the Tag view page, you click edit and it takes you to the Tag edit page. But I want to improve the user experience, so when a user clicks edit, a modal window displays allowing editing of Tag, upon clicking save, modal window closes and AJAX updates Tag view page without refresh. You can see my Tag view.html here which is using Twig template system: {% extends "backendbase.html" %} {% block title %}Manage Tags{% endblock %} {% block body %} <h1 class="ui header">View Tags</h1> {% if tags.errors is not empty %} <div class="ui error message"> <p>Errors:</p> {% for error in tags.errors %} <div>{{ error }}</div> {% endfor %} </div> {% endif %} <table class="ui striped table"> <thead> <tr> <th>Id</th> <th>Tag</th> <th>Directory</th> <th>Synonyms</th> <th>Edit</th> <th>Test</th> <th>Delete</th> </tr> </thead> <tbody> {% for tag in tags %} <tr> <td>{{ tag.id }}</td> <td>{{ tag.tag }}</td> <td>{{ tag.tag_dir }}</td> <td>{{ tag.synonyms }}</td> <td><a class="edit" onclick="return false;" href="../edit/?edit={{ tag.id }}">Edit</a></td> <td><a href="../test/?test={{ tag.id }}">Test</a></td> <td><a href="../delete/?delete={{ tag.id }}">Delete</a></td> </tr> {% endfor %} </tbody> </table> <div class="ui modal"> <i class="close icon"></i> <div class="header"> Edit Tag </div> <div class="image content"> <!--<div class="ui medium image"></div>--> <div class="description"> <!-- <div class="ui header">We've auto-chosen a profile image for you.</div> <p>We've grabbed the following image from the <a href="https://www.gravatar.com" target="_blank">gravatar</a> image associated with your registered e-mail address.</p> <p>Is it okay to use this photo?</p> --> </div> </div> <div class="actions"> <div class="ui black deny button"> Cancel </div> <div class="ui positive right labeled icon button"> Save <i class="checkmark icon"></i> </div> </div> </div> <div class="ui divider"></div> <div class="ui pagination menu"> {% for page in pages %} <a href="{{ page.number|e }}" class="{{ page.isactive|e }}">{{ page.number|e }}</a> {% endfor %} </div> {% endblock %} If I add a form in the modal window with {{ tag.id }} and {{ tag.name }}, nothing displays obviously because it is not in the for in loop. My question is, what is the industry standard way of getting data into this modal window form? I could use a $_GET["id"] but then I am breaking MVC model by including code in template. Is the solution to use JavaScript to get ID from edit link, in the background get data from database then use JavaScript to create form in modal? Your help would be much appreciated! Hello my good people
I'm doing a content manager system in PHP and mySQLi, following a serie of video tutorials.
But in my project I am using a tree menu.
In the front office all works smoothly (the tree menu displays all results - menu and submenus - and each button carries the information of the respective page). I've played around with CakePHP, then XCrud (a decent CRUD application) but I gave up on both of them, XCrud was great for everything up until it came to managing complicated relational database tables. Anyhow, I'm using wordpress a lot now cuz it lets me stop reinventing the wheel so much and although I was able to integrate XCrud into WordPress as a plugin, I think the best way to go is just transfer my database tables to WordPress tables and display them as custom post types. My time is really limited right now though, is there a plugin/set of plugins I can use to automate the process? To show you what I mean, heres the XCrud list display of one of the tables:
thats great because it automatically sets up the CRUD thing and lets you add and edit fields to the table, and doesn't heavily box you into their system but I have a table of plants, one for products, one for pharmacology, one for categories which are all related to each other, and some of them are structured in a tree/nested hierarchy structure so long story short, I need to do advanced searches based on these relations and handle these tree structured tables and CakePHP didn't work out, and XCrud has crappy documentation and isn't popular enough to find good info.
So how would you go about transfering this system to WordPress? I'm guessing I need to make custom post types for each table but what I don't yet know is how to transfer the DB tables to WordPress format, how to handle the relationships between each table and how to handle the hierarchical tree structures.
Hi
I just finished this tutorial('http://www.startutor...torial-part-3/)
and everything was working fine until I decided to add last names to the application.
I got everything working on all the other pages except the Update page.
This is my php code.
Hello I need a great help for my problem, I tried to insert multiple checkboxs for "$_POST active" in my CRUD and the values must be saved in the database but will be saved as "Array" everytime. foreach($_POST['active'] as $act){//query? } Here the PHP code <?php require_once "../lakota/config.php"; if ($_SERVER["REQUEST_METHOD"] == "POST") { if (isset($_POST['faction'], $_POST['stations'], $_POST["active"], $_POST['pending'], $_POST['influence'], $_POST['id_fact'])) { if(isset($_POST["submit"])){ $activearr=$_POST["active"]; $newvalues= implode(",", $activearr); include_once "../lakota/checkboxClass.php"; $checkBoxClass=new checkboxClass(); echo $checkBoxClass->addtoDatabase($newvalues); } $sql = "INSERT INTO lakotabgs (faction, stations, active, pending, influence, id_fact) VALUES (?,?,?,?,?,?)"; if ($stmt = $link->prepare($sql)) { $stmt->bind_param("ssssss", $_POST['faction'], $_POST['stations'], $_POST["active"], $_POST['pending'], $_POST['influence'], $_POST['id_fact']); if ($stmt->execute()) { header("location: ../lakota/index.php"); exit(); } else { echo "Error! Try again later."; } $stmt->close(); } } $link->close(); } ?> HTML code <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Add new info</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> </head> <body> <form action="<?php echo $_SERVER["PHP_SELF"] ?>" method="post"> <label><b>Active States</b></label> <input name="active[]" class="form-control" id="example1" type="checkbox" value="None" /> <label for="example1">None</label> <input name="active[]" class="form-control" id="example2" type="checkbox" value="Everybody" /> <label for="example2">Everybody</label> <input name="active[]" class="form-control" id="example3" type="checkbox" value="Unknown" /> <label for="example3">Unknown</label> <input type="submit" id="submit" name="submit" class="btn btn-primary" value="Add new info"> <a href="../lakota/index.php" class="btn btn-default">Back</a> </form> </body> </html> Edited November 14, 2020 by AccuCORE Hello All,
I've encountered one more problem (with the first WebApp I'm building), and I have no idea how to fix it. I've tried something, but it doesn't seem to work, so I'd appreciate some help in getting it fixed.
Here's what's happening:
So after I perform an operation (let's say "ADDing a record")...the records gets added correctly, but then, if/when I press [F5] in my browser window (or click on the Refresh/Reload icon), the same input details are being used and a second identical record is being added. I believe the same thing happens for some (or perhaps all) of the other CRUD operations.
What do I need to do to disable that behavior?
The only thing I could think of is to set the $functionSelected variable to blank ("") - which I've done towards the bottom of my code (shown below) - but that doesn't seem to be doing anything...the problem persists.
if(isset($_POST['action'])) { $functionSelected = $_POST["action"]; } if(isset($functionSelected)){ switch($functionSelected){ case "insert": $initialize_flag = "N"; // Store POST(ed) user-entered values into memory variables $store_name = $_POST['store_name']; $item_description = $_POST['item_description']; $qty_pkg = $_POST['qty_pkg']; $pkg_of = $_POST['pkg_of']; $price = $_POST['price']; $flyer_page = $_POST['flyer_page']; $limited_time_sale = $_POST['limited_time_sale']; $flyer_date_start = $_POST['flyer_date_start']; $nos_to_purchase = $_POST['nos_to_purchase']; // Setup customized query $sql = "INSERT INTO shoplist (store_name, item_description, qty_pkg, pkg_of, price, flyer_page, limited_time_sale, flyer_date_start, nos_to_purchase, shopper1_buy_flag, shopper2_buy_flag, purchased_flag, purchase_later_flag) VALUES (:store_name, :item_description, :qty_pkg, :pkg_of, :price, :flyer_page, :limited_time_sale, :flyer_date_start, :nos_to_purchase, :shopper1_buy_flag, :shopper2_buy_flag, :purchased_flag, :purchase_later_flag)"; try { $statement = $conn->prepare($sql); $statement->bindParam(':store_name', $store_name); $statement->bindParam(':item_description', $item_description); $statement->bindParam(':qty_pkg', $qty_pkg); $statement->bindParam(':pkg_of', $pkg_of); $statement->bindParam(':price', $price); $statement->bindParam(':flyer_page', $flyer_page); $statement->bindParam(':limited_time_sale', $limited_time_sale); $statement->bindParam(':flyer_date_start', $flyer_date_start); $statement->bindParam(':nos_to_purchase', $nos_to_purchase); $statement->bindParam(':shopper1_buy_flag', $initialize_flag); $statement->bindParam(':shopper2_buy_flag', $initialize_flag); $statement->bindParam(':purchased_flag', $initialize_flag); $statement->bindParam(':purchase_later_flag', $initialize_flag); // Execute the query $statement->execute(); $statement->closeCursor(); $functionSelected = ""; // WILL THIS STATEMENT NOT SERVE TO INITIALIZE/RESET THE OPERATION??? break; } catch (PDOException $e) { print "Error!: " . $e->getMessage() . "<br/>"; } case "update-delete": ... ... ...Thanks. This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=319767.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=346829.0 This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=343318.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=317014.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=328845.0 This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=325953.0 This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=342987.0 This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=353027.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=328753.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=305825.0 |