yankeesjtj Posted March 21, 2008 Share Posted March 21, 2008 Right now I've got a few pages, one to insert a record, another to update a record, one to query by customer and one to query by date. What I'm trying to accomplish is to have one page and let the user choose if they want to insert, update, etc... Taking the code from the working pages, I created a couple of the functions (insert and querybycustomer and tested. It flops like a fish out of water... Any Suggestions would be great <!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> <title>Database administration</title> <body> <h2 align="center">Database administration</h2> <?php function poinsert() { if(isset($_POST['insert'])) { include 'library/po_config.php'; include 'library/opendb.php'; $curr_date = $_REQUEST["curr_date"]; $custname = $_REQUEST["custname"]; $po_quant = $_REQUEST["po_quant"]; $query = "INSERT INTO purch_orders (date, customer_name, po_quantity) VALUES ('$curr_date', '$custname', '$po_quant')"; mysql_query($query) or die("Error in query: $query. ".mysql_error()); $query = "FLUSH PRIVILEGES"; mysql_query($query) or die("Error in query: $query. ".mysql_error()); include 'library/closedb.php'; echo " "; echo "Data Added"; } else { echo <<<HERE <form method="post"> <table align = "center" width="400" border="0" cellspacing="1" cellpadding="2"> <tr> <td width="100">Date (yyyy-mm-dd) : </td> <td><input name="curr_date" type="text" id="curr_date"></td> </tr> <tr> <td width="100">Customer Name</td> <td><select name="custname"> <option value="Wallys Wallets">Wally's Wallets</option> <option value="Franks Fish Farm">Franks Fish Farm</option> <option value="Sals Smoke Shop">Sal's Smoke Shop</option> <option value="Leroys Leather Goods">Leroys Leather Goods</option> <option value="Carls Computers">Carl's Computers</option></td> </tr> <tr> <td width="100">PO Quantity</td> <td><input name="po_quant" type="text" id="po_quant"></td> </tr> <tr> <td width="100"> </td> <td><input name="insert" type="submit" id="add" value="Insert record"></td> </tr> </table> </form> HERE; } }// end function insert function queryByCustomer() { if(isset($_POST['run_query'])) { include 'library/po_config.php'; include 'library/opendb.php'; $custname = $_REQUEST["custname"]; $query = "select date, customer_name, po_quantity from purch_orders where customer_name = '$custname' "; $result = mysql_query($query); include 'library/closedb.php'; echo <<<HERE <table align ="center" width= "30%"> <tr><td colspan="3"><b>Customer Name: $custname</b></td></tr> <tr> <td width ="33%"><b>Date</b></td> <td width ="33%"><b>Quantity</b></td> </tr> </table> <table align= "center" width= "30%"> HERE; while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo <<<HERE <tr> <td width ="33%">{$row['date']}</td> . <td width ="33%">{$row['po_quantity']}</td> </tr> HERE; } //end while echo <<<HERE <tr><td> </td></tr> </table> HERE; } //end if else { echo <<<HERE <form method="post"> <table align = "center" width="400" border="0" cellspacing="1" cellpadding="2"> <tr> <td width="100">Choose Customer to Query: </td> <td><select name="custname"> <option value="Wallys Wallets">Wally's Wallets</option> <option value="Franks Fish Farm">Franks Fish Farm</option> <option value="Sals Smoke Shop">Sal's Smoke Shop</option> <option value="Leroys Leather Goods">Leroys Leather Goods</option> <option value="Carls Computers">Carl's Computers</option></td> </tr> <td width="100"> </td> <td><input name="run_query" type="submit" id="add" value="run_query"></td> </tr> </table> </form> HERE; } } //end function queryByCustomer $op = $_REQUEST["op"]; if(isset($_POST['run_query'])) { switch($op){ case "Insert": poinsert(); break; case "Update": echo "You want to Update a record"; break; case "QCust": queryByCustomer(); break; case "QDate": echo "You want to Query by Date"; break; default: echo "You want to do something else"; } //end switch } //end if else { ?> <form method="post"> <table align = "center" width="400" border="0" cellspacing="1" cellpadding="2"> <tr> <td width ="100">Pick an operation to perform</td> <td<select name="op"> <option value = "Insert">Insert a record</option> <option value = "Update">Update a record</option> <option value = "QCust">Query by Customer</option> <option value = "QDate">Query by Date</option> </td> </tr> <td width="100"> </td> <td><input name="run_query" type="submit" id="add" value="run a query"></td> </tr> </table> </form> <?php } ?> </div> </div> </body> </html> Thanks for they help Link to comment https://forums.phpfreaks.com/topic/97173-update-insert-query-choice-loop/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.