{ "key_pair_value_system": true, "answer_rating_count": "", "question_feedback_html": { "html_star": "", "html_star_feedback": "" }, "answer_average_rating_value": "", "answer_date_js": "2024-09-25T00:08:18-04:00", "answer_date": "2024-09-25 00:08:18", "is_docs_available": "", "is_excel_available": "", "is_pdf_available": "", "count_file_available": 0, "main_page": "student_question_view", "question_id": "13238142", "url": "\/study-help\/questions\/part-1-from-databases-to-forms-read-the-states-from-13238142", "question_creation_date_js": "2024-09-25T00:08:18-04:00", "question_creation_date": "Sep 25, 2024 12:08 AM", "meta_title": "[Solved] Part 1; From databases to forms: read the | SolutionInn", "meta_description": "Answer of - Part 1; From databases to forms: read the states from a database table instead of putting them into a PHP array yourse | SolutionInn", "meta_keywords": "part,1,databases,forms,read,states,database,table,putting,php,array,file", "question_title_h1": "Part 1; From databases to forms: read the states from a database table instead of putting them into a PHP array yourself.(the php file is", "question_title": "Part 1; From databases to forms: read the states from a database", "question_title_for_js_snippet": "Part 1 From databases to forms read the states from a database table instead of putting them into a PHP array yourself (the php file is included down below) The database is named weblab and the table of states is named state t The table was created as follows CREATE TABLE state t ( state abbr char(2) PRIMARY KEY, state name char(20), state zone integer) Display the state name in the drop down, but transmit the state abbreviation through the form You do this by using a value attribute on the element The form area for State will look something like the following Of course, you have to build this using PHP, and not just type it in AlabamaFloridaGeorgiaTennessee You will not use the state zone attribute In real life it would be used for calculating shipping, maybe Present the state names in alphabetical order on your form The easy way to do this is to have the database management system sort them for you using an ORDER BY clause in your SQL For those of you who took Database long ago and far away (or not at all ), a suitable query for populating the array is this SELECT state abbr, state name from state t ORDER BY state name this is my php file My Form table border collapse collapse td padding top 5em padding bottom 5em padding right 1 5em function calcCost() var sum 0 var tax 0 var cwQty document getElementById( crescent wrench ) value var spQty document getElementById( spanners ) value var mwQty document getElementById( monkey wrench ) value if(isNaN(cwQty)) alert( Enter a numeric value for Crescent Wrench Quantity ) return false else if(isNaN(spQty)) alert( Enter a numeric value for spanners Quantity ) return false else if(isNaN(mwQty)) alert( Enter a numeric value for monkey wrench Quantity ) return false else cwQty (cwQty ) parseInt( 0 ) parseInt(cwQty) spQty (spQty ) parseInt( 0 ) parseInt(spQty) mwQty (mwQty ) parseInt( 0 ) parseInt(mwQty) sum (cwQty 15) (spQty 10) (mwQty 12) tax sum 1 07 return confirm( The total cost of your order is $ (sum tax) toFixed(2)) Order Product quantity wanted Product Price Quantity crescent wrench $15 spanners $10 monkey wrench $12 Customer infromation First Name Last Name Shipping address Select State ", "question_description": "

Part 1; From databases to forms:<\/strong> read the states from a database table instead of putting them into a PHP array yourself.(the php file is included down below)<\/p>

The database is named weblab and the table of states is named state_t. The table was created as follows:<\/p>

CREATE TABLE state_t ( state_abbr char(2) PRIMARY KEY, state_name char(20), state_zone integer); <\/pre> 

Display the state name in the drop-down, but transmit the state abbreviation through the form. You do this by using a value<\/em> attribute on the<\/p>

element. The form area for State will look something like the following. Of course, you have to build this using PHP, and not just type it in.<\/p>

AlabamaFloridaGeorgiaTennessee <\/pre> 

You will not use the state_zone attribute. In \"real life\" it would be used for calculating shipping, maybe.<\/p>

Present the state names in alphabetical order on your form. The easy way to do this is to have the database management system sort them for you using an ORDER BY clause in your SQL. For those of you who took Database long ago and far away (or not at all!), a suitable query for populating the array is this:<\/p>

SELECT state_abbr, state_name from state_t ORDER BY state_name; <\/pre> 

this is my php file<\/p>

<\/p>

My Form<\/title> <meta charset=\"UTF-8\" \/><\/p> <p><style type=\"text\/css\"> table { border-collapse: collapse; } td { padding-top: .5em; padding-bottom: .5em; padding-right: 1.5em; } <\/style> <script type=\"text\/javascript\"> function calcCost() { var sum = 0; var tax = 0; var cwQty = document.getElementById(\"crescent_wrench\").value; var spQty = document.getElementById(\"spanners\").value; var mwQty = document.getElementById(\"monkey_wrench\").value;<\/p> <p> if(isNaN(cwQty)){ alert(\"Enter a numeric value for Crescent_Wrench Quantity\"); return false; }else if(isNaN(spQty)){ alert(\"Enter a numeric value for spanners Quantity\"); return false; }else if(isNaN(mwQty)){ alert(\"Enter a numeric value for monkey_wrench Quantity\"); return false; }else{ cwQty = (cwQty == \"\") ? parseInt(\"0\") : parseInt(cwQty); spQty = (spQty == \"\") ? parseInt(\"0\") : parseInt(spQty); mwQty = (mwQty == \"\") ? parseInt(\"0\") : parseInt(mwQty); sum = (cwQty*15) + (spQty*10) + (mwQty*12) ; tax = sum * 1.07; return confirm(\"The total cost of your order is $\" + (sum + tax).toFixed(2)); } }<\/p> <p><\/script><\/p> <p> <link rel=\"shortcut icon\" href=\"\/favicon.ico\" type=\"image\/x-icon\" \/> <link rel=\"stylesheet\" type=\"text\/css\" href= \"l2p1.css\"\/> <\/head> <body> <form action=\"http:\/\/weblab.kennesaw.edu\/formtest.php\" onsubmit=\"return calcCost()\" method=\"post\"> <h3>Order<\/h3> <h4>Product quantity wanted<\/h4><\/p> <p><table> <tr> <th>Product<\/th> <th>Price<\/th> <th>Quantity<\/th> <\/tr> <tr> <td>crescent_wrench<\/td> <td>$15<\/td> <td><input id=\"crescent_wrench\" type=\"text\" name=\"crescent_wrench\" ><\/td> <\/tr> <tr> <td>spanners<\/td> <td>$10<\/td> <td><input id=\"spanners\" type=\"text\" name=\"spanners\"><\/td> <\/tr> <tr> <td>monkey_wrench<\/td> <td>$12<\/td> <td><input id=\"monkey_wrench\" type=\"text\" name=\"monkey_wrench\"><\/td> <\/tr> <\/table> <h4>Customer infromation: <\/h4> <div> <label for=\"firstName\">First Name:<\/label> <input id=\"firstName\" type=\"text\" name=\"FirstName\"> <label for=\"LastName\">Last Name:<\/label> <input id=\"LastName\" type=\"text\" name=\"LastName\"><\/p> <p> <label for=\"address\">Shipping address:<\/label> <input id=\"address\" type=\"text\" name=\"address\"> <\/div><\/p> <p> <select name=\"states\"> <option selected=\"selected\">--- Select State---<\/option> <?php $states=array(\"Georgia\",\"Alabama\",\"Florida\"); foreach($states as $state){ ?> <option value=\"<?php echo strtolower($state);?>\"><?php echo $state;?><\/option>\" <?php } ?> <\/select><\/p> <p> <div> <h4>payement methods: <\/h4> <label for=\"Visa\">Visa: <\/label> <input id=\"Visa\" type=\"radio\" name=\"payement\" value=\"Visa\"><\/p> <p> <label for=\"MasterCard\">MasterCard: <\/label> <input id=\"MasterCard\" type=\"radio\" name=\"payement\" value=\"MasterCard\"><\/p> <p> <label for=\"AmericanExpress\">American Express: <\/label> <input id=\"AmericanExpress\" type=\"radio\" name=\"payement\" value=\"AmericanExpress\"> <\/div><\/p> <p> <p> <input type=\"submit\" value=\"Submit Order\" \/><\/p><\/p> <p><\/form><\/p> <p><\/body> <\/html><\/p>", "transcribed_text": "", "related_book": { "title": null, "isbn": null, "edition": null, "authors": null, "cover_image": null, "uri": null, "see_more_uri": "" }, "question_posted": "2024-09-25 00:08:18", "step_by_step_answer": "The Answer is in the image, click to view ...", "students_also_viewed": [], "next_back_navigation": { "previous": "", "next": "" }, "breadcrumbs": [ { "name": "Study help", "link": "https:\/\/www.solutioninn.com\/study-help\/questions-and-answers" }, { "name": "Computer Science", "link": "https:\/\/www.solutioninn.com\/study-help\/questions-and-answers\/computer-science" }, { "name": "Databases", "link": "https:\/\/www.solutioninn.com\/study-help\/questions\/computer-science-databases" }, { "name": "Part 1; From databases to forms: read the states from a database", "link": "https:\/\/www.solutioninn.com\/study-help\/questions\/part-1-from-databases-to-forms-read-the-states-from-13238142" } ], "skill_details": { "skill_id": "656", "skill_name": "Databases", "parent_id": "8" } }