215k views
4 votes
Need help with this HTML/PHP code, I tried many different things but my PHP code is not working.

Create an HTML form with the following features:

a. A textbox for the user to input the value to be converted

b. A set of radio buttons for the user to select the currency to be converted from

i. Currency types should be: CAN, USD, EUR, GBP, CHY

ii. The corresponding flag icon should be displayed beside each currency option

c. A set of radio buttons for the user to select the currency to be converted to

i. Currency types should be: CAN, USD, EUR, GBP, CHY

ii. The corresponding flag icon should be displayed beside each currency option: =

d. A submit button Write a PHP script which takes the user input (amount, converting from currency, converting to currency) and applies an appropriate conversion.

e. A conversion to and from the same currency should result in the same amount before and after conversion f. Error checking must be implemented to ensure that the user is notified if the input is not a number

User Jaylon
by
8.2k points

1 Answer

4 votes

Final answer:

To build an HTML form with PHP for currency conversion, include input and radio elements for amount and currency choices, and use PHP to handle the data with error checking for numeric input.

Step-by-step explanation:

Creating an HTML Form with PHP for Currency Conversion

To create an HTML form that allows users to input a value for conversion and select currencies with radio buttons, follow this structure. Include a textbox for the amount to be converted and radio button groups for selecting the currency to convert from and currency to convert to, accompanied by their respective flag icons. Your PHP script will process this form, perform the appropriate conversions, and include error checking to ensure numeric input.

HTML code for the form will include elements such as <input>, <radio>, and <form> tags. In the PHP script, you will retrieve the form data using the $_POST superglobal. To check if the input is not a number, you can use the is_numeric function. If the currencies to convert from and to are the same, your script should return the original amount.

Error checking is crucial. If the user inputs a non-numeric value or fails to select a currency, display an error message. Remember to check if the form has been submitted by checking if the submit button has been pressed (e.g., checking the $_POST['submit'] variable).

User Brian Rudolph
by
8.5k points